#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxm = 25, mmask = (1 << 20) + 10;
int n, a[maxn], cnt[maxm], d, m;
bool mark[mmask];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> d;
  for (int i = 0, k, t; i < m; ++i) {
    cin >> t;
    while (t--) {
      cin >> k;
      a[k] = i;
    }
  }
  int mask = 1 << m, b = 0;
  for (int i = 1; i <= n; ++i) {
    if (!cnt[a[i]]++) b ^= (1 << a[i]);
    if (i > d && !--cnt[a[i - d]]) b ^= (1 << a[i - d]);
    if (i >= d) ++mark[~b & (mask - 1)];
  }
  int ans = m;
  for (int i = mask - 1; ~i; --i) {
    for (int j = 0; j < m; ++j) mark[i] |= mark[i | (1 << j)];
    if (!mark[i]) ans = min(ans, __builtin_popcount(i));
  }
  cout << ans << '\n';
  return 0;
}
