#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 7;
const int MAX_M = 20 + 1;
bool dp[1 << MAX_M];
int belong[MAX_N], cnt[MAX_M];
int main() {
  int N, M, D;
  scanf("%d%d%d", &N, &M, &D);
  for (int i = 0; i < M; i++) {
    int c;
    scanf("%d", &c);
    while (c--) {
      int x;
      scanf("%d", &x);
      belong[x] = i;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i > D) cnt[belong[i - D]]--;
    cnt[belong[i]]++;
    if (i >= D) {
      int mask = 0;
      for (int j = 0; j < M; j++) {
        if (cnt[j] == 0) mask |= (1 << j);
      }
      dp[mask] = 1;
    }
  }
  int ans = M;
  for (int st = (1 << M) - 1; st >= 0; st--) {
    if (!dp[st]) {
      ans = min(ans, __builtin_popcount(st));
      continue;
    }
    for (int i = 0; i < M; i++) {
      if ((st >> i) & 1) dp[st ^ (1 << i)] = 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
