#include <bits/stdc++.h>
using namespace std;
int from[100010], dp[1 << 20], use[20];
int ck(int s) {
  int ans = 0;
  while (s) {
    ans++;
    s -= (s & -s);
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < x; j++) {
      int val;
      scanf("%d", &val);
      from[val] = i;
    }
  }
  memset(use, 0, sizeof(use));
  int s = 0;
  for (int i = 1; i <= d - 1; i++) {
    use[from[i]]++;
    if (use[from[i]] == 1) s |= (1 << from[i]);
  }
  int S = (1 << m) - 1;
  for (int i = d; i <= n; i++) {
    use[from[i]]++;
    if (use[from[i]] == 1) s |= (1 << from[i]);
    dp[S & (~s)] = 0;
    use[from[i - d + 1]]--;
    if (use[from[i - d + 1]] == 0) s ^= (1 << from[i - d + 1]);
  }
  int ans = m;
  for (int i = S; i >= 0; i--) {
    if (dp[i] == 0) {
      for (int j = 0; j < m; j++) {
        if (i & (1 << j)) dp[i ^ (1 << j)] = 0;
      }
    } else {
      ans = min(ans, ck(i));
    }
  }
  printf("%d\n", ans);
  return 0;
}
