#include <bits/stdc++.h>
using namespace std;
int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int maxn = 21;
vector<int> vc[maxn];
vector<int> nxt[maxn];
int sz[maxn];
int32_t main() {
  int n = in(), m = in(), d = in();
  for (int i = 0; i < m; i++) {
    sz[i] = in();
    for (int pt = 0; pt < sz[i]; pt++) vc[i].push_back(in());
    sort(vc[i].begin(), vc[i].end());
    nxt[i].resize(sz[i]);
    for (int pt = sz[i] - 1; pt >= 0; pt--) {
      int nextNumber = upper_bound(vc[i].begin(), vc[i].end(), vc[i][pt] + d) -
                       vc[i].begin() - 1;
      if (nextNumber > pt)
        nxt[i][pt] = nxt[i][nextNumber];
      else
        nxt[i][pt] = pt;
    }
  }
  int res = m + 1;
  for (int mask = 1; mask < (1 << m); mask++) {
    int number = 0;
    bool can = true;
    if (__builtin_popcount(mask) > res) continue;
    while (number + d <= n) {
      bool fl = false;
      for (int pt = 0; pt < m; pt++) {
        if (mask >> pt & 1) {
          int low = lower_bound(vc[pt].begin(), vc[pt].end(), number + 1) -
                    vc[pt].begin();
          if (low < sz[pt] && vc[pt][low] - number <= d) {
            int id = nxt[pt][low];
            fl = true;
            number = vc[pt][id];
          }
        }
      }
      if (fl == false) {
        can = false;
        break;
      }
    }
    if (can) res = min(res, __builtin_popcount(mask));
  }
  if (res == m + 1)
    cout << -1 << endl;
  else
    cout << res << endl;
}
