#include <bits/stdc++.h>
using namespace std;
int c[21][100010];
int cn[21], d;
int p[100010];
bool a[21][1 << 20];
vector<int> e[1 << 20];
int dp[1 << 21];
bool find(int ci, int x) {
  int l = -1, r = cn[ci] - 1, z;
  if (r < 0 || c[ci][r] <= x) return false;
  while (l + 1 < r) {
    z = (l + r) >> 1;
    if (c[ci][z] <= x)
      l = z;
    else
      r = z;
  }
  return c[ci][r] - x <= d;
}
int m;
int dfs(int x) {
  if (dp[x] >= 0) return dp[x];
  int i, t = -1;
  dp[x] = 1000;
  for (i = 0; i <= m; i++) {
    if ((x & (1 << i)) && a[i][(1 << m) ^ x]) {
      t = i;
      break;
    }
  }
  if (t == -1) return dp[x] = 0;
  for (i = 0; i < m; i++) {
    if (x & (1 << i)) continue;
    dp[x] = min(dp[x], dfs(x | (1 << i)) + 1);
  }
  return dp[x];
}
int main() {
  int n, i, j, k, x;
  scanf("%d%d%d", &n, &m, &d);
  cn[m] = 2;
  c[m][0] = 0;
  c[m][1] = n + 1;
  p[0] = p[n + 1] = m;
  for (i = 0; i < m; i++) {
    scanf("%d", &cn[i]);
    for (j = 0; j < cn[i]; j++) {
      scanf("%d", &x);
      c[i][j] = x;
      p[x] = i;
    }
    sort(c[i], c[i] + cn[i]);
  }
  int mm = (1 << m) - 1;
  for (i = 0; i <= n; i++) {
    if (n + 1 - i <= d) break;
    x = p[i];
    if (find(x, i)) continue;
    x = 0;
    for (j = 0; j < m; j++) {
      if (find(j, i)) x |= (1 << j);
    }
    a[p[i]][mm ^ x] = true;
  }
  for (i = 0; i <= mm; i++) {
    for (j = 0; j < m; j++) {
      if (i & (1 << j)) {
        e[i].push_back(i ^ (1 << j));
      }
    }
  }
  for (i = 0; i <= m; i++) {
    for (j = mm; j >= 0; j--) {
      if (a[i][j]) {
        for (k = 0; k < (int)e[j].size(); k++) {
          a[i][e[j][k]] = true;
        }
      }
    }
  }
  for (i = 0; i < (1 << (m + 1)); i++) dp[i] = -1;
  printf("%d\n", dfs(1 << m));
  return 0;
}
