#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
const int M = 20;
int cnt[M];
int id[N];
int n, m, d;
bool dp[1 << M];
int bits_cnt[1 << M];
int main() {
  bits_cnt[0] = 0;
  for (int i = 1; i < 1 << M; i++) {
    bits_cnt[i] = bits_cnt[i >> 1] + (i & 1);
  }
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    int k, x;
    scanf("%d", &k);
    while (k--) {
      scanf("%d", &x);
      id[x] = i;
    }
  }
  int mask = 0, all = (1 << m) - 1;
  for (int i = 1; i <= d - 1; i++) {
    cnt[id[i]]++;
    mask |= 1 << id[i];
  }
  for (int i = d; i <= n; i++) {
    cnt[id[i]]++;
    mask |= 1 << id[i];
    dp[all ^ mask] = true;
    int x = id[i - d + 1];
    if (--cnt[x] == 0) mask ^= 1 << x;
  }
  int ans = m;
  for (int i = all; i > 0; i--) {
    if (dp[i]) {
      for (int j = 0; j < m; j++) {
        if (i >> j & 1) dp[i ^ (1 << j)] = true;
      }
    } else
      ans = min(ans, bits_cnt[i]);
  }
  cout << ans << endl;
  return 0;
}
