#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int a[100010], b[100010];
int f[1 << 20];
void get() {
  int st = 0;
  for (int i = 1; i <= m; i++)
    if (!b[i]) st |= 1 << i - 1;
  f[st] = 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    int t;
    scanf("%d", &t);
    for (int j = 1; j <= t; j++) {
      int p;
      scanf("%d", &p);
      a[p] = i;
    }
  }
  for (int j = 1; j <= d; j++) b[a[j]]++;
  get();
  for (int j = d + 1; j <= n; j++) b[a[j - d]]--, b[a[j]]++, get();
  int ans = m;
  for (int i = (1 << m) - 1; i >= 0; i--)
    if (f[i]) {
      for (int j = 0; j < m; j++)
        if (i & (1 << j)) f[i ^ (1 << j)] = 1;
    } else
      ans = min(ans, __builtin_popcount(i));
  printf("%d\n", ans);
}
