#include <bits/stdc++.h>
using namespace std;
bool dp[1 << 20];
int n, m, d;
void read() {
  static int pos[100010], cnt[100010];
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1, p; i <= m; ++i) {
    scanf("%d", &p);
    for (int j = p; j >= 1; --j) {
      scanf("%d", &p);
      pos[p] = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    ++cnt[pos[i]];
    if (i > d) --cnt[pos[i - d]];
    int S = 0;
    for (int j = 1; j <= m; ++j)
      if (cnt[j]) S = 1 << (j - 1) | S;
    if (i >= d) dp[S] = true;
  }
}
int Dp() {
  int S = (1 << m) - 1, ans = 1 << 30;
  for (int i = 0; i <= S; ++i) {
    for (int j = 0; j < m; ++j) dp[1 << j | i] |= dp[i];
    if (!dp[i]) {
      int tot = m;
      for (int j = i; j; j -= j & (-j)) --tot;
      ans = min(ans, tot);
    }
  }
  return ans;
}
int main() {
  read();
  printf("%d\n", Dp());
  return 0;
}
