#include <bits/stdc++.h>
int id[100010];
int cnt[100010][30];
bool f[1 << 20];
int main() {
  int i, j, n, m, k, d, as, x;
  scanf("%d%d%d", &n, &m, &d);
  for (i = 0; i < m; i++)
    for (scanf("%d", &k); k--;) {
      scanf("%d", &x);
      id[x] = i;
    }
  for (i = 1; i <= n; i++)
    for (j = 0; j < m; j++) cnt[i][j] = cnt[i - 1][j] + (id[i] == j);
  for (i = d; i <= n; i++) {
    k = 0;
    for (j = 0; j < m; j++)
      if (cnt[i][j] - cnt[i - d][j] == 0) k |= 1 << j;
    f[k] = 1;
  }
  as = m;
  for (i = (1 << m) - 1; i > 0; i--)
    if (f[i]) {
      for (j = 0; j < m; j++)
        if (i >> j & 1) f[i ^ (1 << j)] = 1;
    } else
      as = as < __builtin_popcount(i) ? as : __builtin_popcount(i);
  ;
  printf("%d\n", as);
  return 0;
}
