#include <bits/stdc++.h>
int N, M, D, S, a[100005], c[100005];
bool b[1 << 21];
int main() {
  scanf("%d%d%d", &N, &M, &D), S = (1 << M) - 1;
  for (int i = 0, s, x; i < M; i++)
    for (scanf("%d", &s); s; s--) scanf("%d", &x), a[x] = i;
  for (int i = 1, x = 0; i <= N; i++) {
    c[a[i]]++, x |= 1 << a[i];
    if (i - D >= 1 && !--c[a[i - D]]) x ^= 1 << a[i - D];
    if (i >= D) b[S ^ x] = 1;
  }
  int ans = M;
  for (int i = S - 1; i; i--)
    if (!b[i])
      ans = std::min(ans, __builtin_popcount(i));
    else
      for (int j = 0; j < M; j++)
        if ((i >> j) & 1) b[i ^ (1 << j)] = 1;
  printf("%d\n", ans);
}
