#include <bits/stdc++.h>
using namespace std;
int n, m, d, whe[100100], size[110], mark, num[110], ans = (1 << 30);
bool bad[1 << 21], bad2[1 << 21];
void add(int node) {
  node = whe[node];
  if (!size[node]) mark |= num[node];
  size[node]++;
}
void push(int node) {
  node = whe[node];
  size[node]--;
  if (!size[node]) mark ^= num[node];
}
void update(int x) {
  int tot = 0;
  while (x) {
    if (x & 1) tot++;
    x >>= 1;
  }
  if (tot < ans) ans = tot;
}
int main() {
  cin >> n >> m >> d;
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      whe[y] = i;
    }
  }
  num[1] = 1;
  for (int i = 2; i <= m + 1; i++) num[i] = num[i - 1] << 1;
  for (int i = 1; i <= d; i++) add(i);
  bad[mark ^ (num[m + 1] - 1)] = 1;
  for (int i = d + 1; i <= n; i++) {
    push(i - d);
    add(i);
    bad[mark ^ (num[m + 1] - 1)] = 1;
  }
  for (int i = num[m + 1] - 1; i; i--)
    if (!bad2[i])
      if (!bad[i])
        update(i);
      else
        for (int s0 = i; s0; s0 = (s0 - 1) & i) bad2[s0] = 1;
  cout << ans;
}
