#include <bits/stdc++.h>
using namespace std;
int n, m, d, a[111111], h[1 << 21], cnt[22], S;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; ++i) {
    int t, x;
    scanf("%d", &t);
    for (; t--;) scanf("%d", &x), a[x] = i;
  }
  S = (1 << m) - 1;
  for (int i = 1, s = 0; i <= n; ++i) {
    if (i > d)
      if ((--cnt[a[i - d]]) == 0) s -= (1 << a[i - d]);
    ++cnt[a[i]];
    s |= (1 << a[i]);
    if (i >= d) h[S ^ s] = 1;
  }
  int ans = m;
  for (int s = S; s >= 0; --s) {
    if (!h[s]) {
      int ret = 0;
      for (int j = 0; j < m; ++j)
        if (s & (1 << j)) ret++;
      ans = min(ans, ret);
    } else {
      for (int j = 0; j < m; ++j)
        if (s & (1 << j)) h[s - (1 << j)] = 1;
    }
  }
  printf("%d\n", ans);
}
