#include <bits/stdc++.h>
using namespace std;
const int K = 21, N = int(1e5);
int belong[N], freq[K], n, k, d;
bool invalid[1 << K];
int main() {
  scanf("%d%d%d", &n, &k, &d);
  for (int i = 1; i <= k; ++i) {
    int m, a;
    scanf("%d", &m);
    while (m--) {
      scanf("%d", &a);
      belong[a] = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    freq[belong[i]]++;
    if (i > d) freq[belong[i - d]]--;
    if (i >= d) {
      int m = 0;
      for (int j = 1; j <= k; ++j)
        if (!freq[j]) m |= 1 << (j - 1);
      invalid[m] = true;
    }
  }
  int res = k;
  for (int i = (1 << k) - 1; i >= 0; --i) {
    if (!invalid[i])
      res = min(res, __builtin_popcount(i));
    else
      for (int j = 0; j < k; ++j)
        if (i & (1 << j)) invalid[i ^ (1 << j)] = true;
  }
  printf("%d\n", res);
}
