#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20) + 10;
int n, m, d;
int a[N], cnt[22];
bool f[N];
inline int get(int x) {
  int ret = 0;
  while (x) {
    ret++;
    x ^= x & -x;
  }
  return ret;
}
int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 0, c, x; i < m; ++i) {
    scanf("%d", &c);
    for (int j = 0; j < c; ++j) scanf("%d", &x), a[x] = i;
  }
  int p = 0, mask = (1 << m) - 1;
  for (int i = 1; i <= n; ++i) {
    p |= 1 << a[i];
    cnt[a[i]]++;
    if (i > d) {
      if (!--cnt[a[i - d]]) p ^= 1 << a[i - d];
    }
    if (i >= d) f[mask ^ p] = true;
  }
  for (int i = mask - 1; i >= 0; --i)
    if (f[i])
      for (int j = 0; j < m; ++j)
        if (i >> j & 1) f[1 << j ^ i] = true;
  int ans = m;
  for (int i = 0; i < mask; ++i) {
    if (!f[i]) ans = min(ans, get(i));
  }
  cout << ans << endl;
  return 0;
}
