#include <bits/stdc++.h>
using namespace std;
const int MAXM = 20;
const long MAXS = 1 << MAXM;
const int MAXN = (int)1e5 + 7;
vector<bitset<MAXM> > war[MAXM + 1][MAXM];
bitset<MAXM> allwar[MAXN];
int m, n, d;
bitset<MAXS> chk;
bitset<MAXS> ok;
void init() {
  cin >> n >> m >> d;
  for (int i = 0; i < (m); ++i) {
    int cnt;
    cin >> cnt;
    vector<int> nums(cnt);
    for (int j = 0; j < (cnt); ++j) {
      cin >> nums[j];
      nums[j] -= 1;
    }
    sort((nums).begin(), (nums).end());
    int nnr = 0;
    int last_nr = -1;
    for (int it = 0; it < (n); ++it) {
      if (nums[nnr] == it) {
        last_nr = it;
        ++nnr;
      }
      if (it - last_nr <= d - 1) allwar[it].set(i);
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      if (!allwar[i].test(j)) war[allwar[i].count()][j].push_back(allwar[i]);
    }
  }
  bitset<MAXM> al;
  for (int i = 0; i < (m); ++i) {
    al.set();
  }
  unsigned long long nr = al.to_ullong();
  chk.set(nr);
  ok.set(nr);
}
bool check(bitset<MAXM> fam) {
  unsigned long long nr = fam.to_ullong();
  if (!chk.test(nr)) {
    chk.set(nr);
    int fe = 0;
    while (fam.test(fe)) ++fe;
    int ff = 0;
    while (!fam.test(ff)) ++ff;
    bitset<MAXM> fam2 = fam;
    fam2.set(fe);
    if (check(fam2)) {
      int siz = fam.count();
      bool flag = true;
      for (int j = (1); j <= (m - siz); ++j) {
        for (int i = 0; i < (war[j][ff].size()); ++i) {
          if ((war[j][ff][i] & fam).none()) {
            flag = false;
            break;
          }
        }
        if (!flag) break;
      }
      if (flag) ok.set(nr);
    }
  }
  return ok.test(nr);
}
bool add(bitset<MAXM> fm, int lst, int mr) {
  if (mr > (m - 1) - lst) return false;
  if (mr == 0) return check(fm);
  for (int i = (lst + 1); i <= (m - mr); ++i) {
    bitset<MAXM> fam = fm;
    fam.set(i);
    if (add(fam, i, mr - 1)) return true;
  }
  return false;
}
int solution() {
  bitset<MAXM> current;
  for (int i = (1); i <= (m - 1); ++i) {
    if (add(current, -1, i)) return i;
  }
  return m;
}
int main() {
  init();
  cout << solution() << endl;
}
