#include <bits/stdc++.h>
using namespace std;
int n, m, d, i, s, x, q, h, ans, j, p, to[110000], now[50];
bool cover[25][1 << 21];
void read(int &x) {
  char k;
  for (k = getchar(); k <= 32; k = getchar())
    ;
  for (x = 0; '0' <= k; k = getchar()) x = x * 10 + k - '0';
}
void dfs(int k, int s, int now) {
  if (k > m) {
    for (int i = 0; i <= m; i++)
      if (now & (1 << i) && cover[i][now]) return;
    ans = ((ans) < (s) ? (ans) : (s));
  } else {
    dfs(k + 1, s, now);
    dfs(k + 1, s + 1, now + (1 << k));
  }
}
int main() {
  read(n);
  read(m);
  read(d);
  for (i = 1; i <= m; i++) {
    read(s);
    while (s--) {
      read(x);
      to[x] = i;
    }
  }
  to[0] = to[n + 1] = 0;
  q = -d;
  h = -1;
  for (i = 1; i <= n + 1; i++) {
    while (q < i - d) {
      if (q >= 0) now[to[q]]--;
      q++;
    }
    while (h < i - 1) {
      ++h;
      if (h <= n + 1) now[to[h]]++;
    }
    for (s = j = 0; j <= m; j++)
      if (now[j]) s += (1 << j);
    cover[to[i]][(1 << (m + 1)) - 1 - s] = true;
  }
  for (i = 0; i <= m; i++)
    for (j = ((1 << (m + 1)) - 1); j >= 0; j--)
      if (cover[i][j])
        for (p = j; p; p -= p & -p) cover[i][j - (p & -p)] = true;
  ans = m;
  dfs(1, 0, 1);
  printf("%d\n", ans);
}
