#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
const int M = 22;
int n, m, d;
int id[N];
int num[M];
int vis[1 << 22];
int bit(int s) {
  int ans = 0;
  while (s) {
    if (s & 1) ++ans;
    s /= 2;
  }
  return ans;
}
int main() {
  while (scanf("%d%d%d", &n, &m, &d) != EOF) {
    for (int i = 0; i < m; ++i) {
      int p, x;
      scanf("%d", &p);
      for (int j = 0; j < p; ++j) {
        scanf("%d", &x);
        id[x] = i;
      }
    }
    memset(num, 0, sizeof(num));
    memset(vis, 0, sizeof(vis));
    int sta = 0;
    for (int i = 1; i <= n; ++i) {
      ++num[id[i]];
      sta |= (1 << id[i]);
      if (i > d) {
        --num[id[i - d]];
        if (num[id[i - d]] == 0) sta ^= (1 << id[i - d]);
      }
      if (i >= d) vis[sta] = 1;
    }
    int ans = 0;
    for (int i = 0; i < (1 << m); ++i) {
      if (vis[i]) {
        for (int j = 0; j < m; ++j) vis[i | (1 << j)] = 1;
      } else {
        ans = max(ans, bit(i));
      }
    }
    printf("%d\n", m - ans);
  }
  return 0;
}
