#include <bits/stdc++.h>
using namespace std;
int ans, n, m, t1, d, i, x, j, mx, now, cnt[1200001], f[1200001], v[1200001],
    mp[1200001];
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (i = 0; i < m; i++) {
    scanf("%d", &t1);
    while (t1--) {
      scanf("%d", &x);
      v[x] = i;
    }
  }
  mx = (1 << m) - 1;
  for (i = 1; i <= n; i++) {
    if (!mp[v[i]]) now ^= 1 << v[i];
    mp[v[i]]++;
    if (i > d) {
      mp[v[i - d]]--;
      if (!mp[v[i - d]]) now ^= 1 << v[i - d];
    }
    if (i >= d) f[mx ^ now] = 1;
  }
  ans = m;
  for (i = 1; i <= mx; i++) cnt[i] = cnt[i >> 1] + (i & 1);
  for (i = mx; i; i--) {
    for (j = 0; j < m; j++) f[i] |= f[i | (1 << j)];
    if (!f[i]) ans = min(ans, cnt[i]);
  }
  printf("%d", ans);
}
