#include <bits/stdc++.h>
using namespace std;
int n, m, d;
vector<int> mask_and[25];
vector<int> ttt;
vector<int> all_num[25];
bool check(int msk) {
  random_shuffle(ttt.begin(), ttt.end());
  for (int i = 0; i < ttt.size(); i++) {
    int nw = ttt[i];
    for (int j = 0; j < mask_and[nw].size(); j++)
      if (!(msk & mask_and[nw][j])) return false;
  }
  return true;
}
void precal(void) {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < all_num[i].size(); j++) {
      if (all_num[i][j] <= d) continue;
      if (j && all_num[i][j] - all_num[i][j - 1] <= d) continue;
      int mm = 0;
      for (int k = 0; k < m; k++) {
        if (k == i) continue;
        vector<int>::iterator it =
            lower_bound(all_num[k].begin(), all_num[k].end(), all_num[i][j]);
        if (it == all_num[k].begin()) continue;
        it--;
        if (all_num[i][j] - *it <= d) mm ^= (1 << k);
      }
      mask_and[i].push_back(mm);
    }
    random_shuffle(mask_and[i].begin(), mask_and[i].end());
  }
}
vector<int> allmask;
int pr[2000005];
bool cmp(int a, int b) { return pr[a] < pr[b]; }
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &d);
  int i, j;
  for (i = 0; i < m; i++) {
    int tot;
    scanf("%d", &tot);
    for (j = 0; j < tot; j++) {
      int x;
      scanf("%d", &x);
      all_num[i].push_back(x);
    }
    sort(all_num[i].begin(), all_num[i].end());
  }
  precal();
  int tot = (1 << m);
  for (i = 0; i < tot; i++) {
    pr[i] = __builtin_popcount(i);
    allmask.push_back(i);
  }
  sort(allmask.begin(), allmask.end(), cmp);
  for (i = 1; i < tot; i++) {
    ttt.clear();
    int msk = allmask[i];
    int mx = 0;
    for (j = 0; j < m; j++)
      if (msk & (1 << j)) {
        ttt.push_back(j);
        mx = max(mx, all_num[j][all_num[j].size() - 1]);
      }
    if (mx < n - d + 1) continue;
    if (check(msk)) break;
  }
  cout << pr[allmask[i]] << endl;
  return 0;
}
