#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int gr[100100];
int rep[100100];
int val[(1 << 20) + 100];
int dp[(1 << 20) + 100][21];
bool f(int x, int in) {
  if (in == m) return val[x];
  if (dp[x][in] != -1) return dp[x][in];
  bool r = f(x, in + 1);
  if (!(x & (1 << in))) {
    r = r || f(x | (1 << in), in + 1);
  }
  return dp[x][in] = r;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m >> d;
  int k;
  int x;
  for (int i = 0; i < m; i++) {
    cin >> k;
    while (k--) {
      scanf("%d", &x);
      gr[x] = i;
    }
  }
  x = (1 << m) - 1;
  for (int i = 1; i <= d; i++) {
    if (!rep[gr[i]]) x -= (1 << gr[i]);
    rep[gr[i]]++;
  }
  val[x] = 1;
  for (int i = d + 1; i <= n; i++) {
    rep[gr[i - d]]--;
    if (!rep[gr[i - d]]) x |= (1 << gr[i - d]);
    if (!rep[gr[i]]) x -= (1 << gr[i]);
    rep[gr[i]]++;
    val[x] = 1;
  }
  int mn = m;
  for (int i = 1; i < (1 << m); i++) {
    if (!f(i, 0)) {
      int r = 0;
      for (int j = 0; j < m; j++) {
        r += (i & (1 << j)) != 0;
      }
      mn = min(mn, r);
    }
  }
  cout << mn << endl;
  return 0;
}
