#include <bits/stdc++.h>
using namespace std;
int dp[1 << 21];
int n, m, d, a[100010];
void dfs(int x) {
  if (dp[x] + 1) return;
  dp[x] = 0;
  for (int i = 0; i < m; i++) {
    if (x & (1 << i)) {
      dfs(x ^ (1 << i));
    }
  }
  return;
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  memset(dp, -1, sizeof(dp));
  int cnt[21] = {};
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 0; j < cnt; j++) {
      int x;
      scanf("%d", &x);
      a[x] = i;
    }
  }
  int Bit = (1 << m) - 1;
  for (int i = 1; i <= n; i++) {
    if (i > d) cnt[a[i - d]]--;
    cnt[a[i]]++;
    if (i < d) continue;
    int s = 0;
    for (int j = 0; j < m; j++)
      if (cnt[j] > 0) s |= 1 << j;
    dfs(s ^ Bit);
  }
  int ret = m;
  for (int i = 0; i < Bit; i++) {
    if (dp[i]) {
      int cnt = 0;
      for (int j = 0; j < m; j++)
        if (i & (1 << j)) cnt++;
      ret = min(ret, cnt);
    }
  }
  cout << ret << endl;
  return 0;
}
