#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
bool bad[(1 << 20) + 10];
int belong[maxn], frequent[21];
int main() {
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    int s, x;
    scanf("%d", &s);
    while (s--) {
      scanf("%d", &x);
      belong[x] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i > d) frequent[belong[i - d]]--;
    frequent[belong[i]]++;
    if (i >= d) {
      int mask = 0;
      for (int j = 0; j < m; j++) {
        if (!frequent[j]) {
          mask |= (1 << j);
        }
      }
      bad[mask] = 1;
    }
  }
  int ans = m + 1;
  for (int i = (1 << m) - 1; i >= 0; i--) {
    if (bad[i]) {
      for (int j = 0; j < m; j++) {
        if (i & (1 << j)) bad[i ^ (1 << j)] = 1;
      }
    } else
      ans = min(ans, __builtin_popcount(i));
  }
  printf("%d\n", ans);
  return 0;
}
