#include <bits/stdc++.h>
using namespace std;
int start[20 + 5], finish[20 + 5], d, n, m;
int label[100000 + 5], f[(1 << 20) + 5], g[(1 << 20) + 5],
    cnt[100000 + 5][20 + 2];
void input() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    finish[i] = 0;
    start[i] = n + 1;
    int sz;
    scanf("%d", &sz);
    while (sz > 0) {
      int t;
      scanf("%d", &t);
      label[t] = i;
      start[i] = min(start[i], t);
      finish[i] = max(finish[i], t);
      sz--;
    }
  }
}
void prepare() {
  int ans = n;
  for (int t = 0; t < m; t++)
    for (int i = 1; i <= n; i++) cnt[i][t] = (cnt[i - 1][t] + (label[i] == t));
  for (int i = 1; i <= n; i++)
    if (i <= n - d) {
      int mask = 0;
      for (int t = 0; t < m; t++)
        if (cnt[i + d][t] > cnt[i][t]) mask |= 1 << t;
      f[mask] |= 1 << label[i];
    }
  for (int i = m - 1; i >= 0; i--) {
    for (int mask = 0; mask < (1 << m); mask++) g[mask] = f[mask];
    for (int mask = 0; mask < (1 << m); mask++)
      if (mask & 1 << i)
        f[mask] = (g[mask] | g[mask ^ 1 << i]);
      else
        f[mask] = g[mask];
  }
  for (int mask = 0; mask < (1 << m); mask++) {
    int min_Val = n + 1, max_Val = 0, cmask = 0, ret = 0;
    for (int i = 0; i < m; i++)
      if (mask & 1 << i) {
        min_Val = min(min_Val, start[i]);
        max_Val = max(max_Val, finish[i]);
        ret++;
      } else
        cmask |= 1 << i;
    if ((f[cmask] & mask) == 0 && min_Val <= d && max_Val >= n - d + 1)
      ans = min(ans, ret);
  }
  printf("%d", ans);
}
int main() {
  input();
  prepare();
}
