#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T>
T gcd(T x, T y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
template <typename T>
vector<pair<T, int>> runLength(const T a[], int n) {
  vector<pair<T, int>> r;
  if (n <= 0) return r;
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    if (i == n || (i != 0 && a[i] != a[i - 1])) {
      r.push_back(make_pair(a[i - 1], cnt));
      cnt = 0;
    }
    cnt++;
  }
  return r;
}
struct Factor {
  int pi;
  int q;
  long long mask;
};
int main() {
  int n;
  int m;
  mt19937 re;
  while (~scanf("%d%d", &n, &m)) {
    const int K = 40;
    vector<vector<int>> seqs(n);
    for (int(i) = 0; (i) < (int)(n); ++(i)) {
      int k;
      scanf("%d", &k);
      seqs[i].resize(k);
      for (int(j) = 0; (j) < (int)(k); ++(j)) scanf("%d", &seqs[i][j]);
    }
    int P = K;
    vector<vector<Factor>> factors(K + 1);
    for (int(k) = (int)(1); (k) <= (int)(K); ++(k)) {
      for (int(pi) = 0; (pi) < (int)(P); ++(pi)) {
        int p = (pi + 1);
        int q = p;
        if (gcd(k, q) == 1) continue;
        long long mask = 0;
        for (int i = 0;;) {
          mask |= 1LL << i;
          (i += k) %= p;
          if (i == 0) break;
        }
        factors[k].push_back(Factor{pi, q, mask});
      }
    }
    vector<vector<int>> occurs(m + 1);
    vector<bool> vis(m + 1);
    for (int(i) = 0; (i) < (int)(n); ++(i)) {
      for (int a : seqs[i])
        if (!vis[a]) {
          vis[a] = true;
          occurs[a].push_back(i);
        }
      for (int a : seqs[i]) vis[a] = false;
    }
    vector<int> indices;
    vector<vector<long long>> masks(P);
    for (int(a) = (int)(1); (a) <= (int)(m); ++(a)) {
      for (int(pi) = 0; (pi) < (int)(P); ++(pi)) {
        masks[pi].clear();
        masks[pi].resize(occurs[a].size());
      }
      for (int(oi) = 0; (oi) < (int)(occurs[a].size()); ++(oi)) {
        int i = occurs[a][oi];
        int k = seqs[i].size();
        indices.clear();
        for (int(t) = 0; (t) < (int)(k); ++(t))
          if (seqs[i][t] == a) indices.push_back(t);
        assert(!indices.empty());
        for (int(pi) = 0; (pi) < (int)(P); ++(pi))
          masks[pi][oi] = (1LL << (pi + 1)) - 1;
        for (auto f : factors[k]) {
          int pi = f.pi, p = pi + 1, q = f.q;
          long long mask = f.mask;
          long long total = 0;
          for (int t : indices) {
            total |= mask << (t % q);
            if (t % q != 0) total |= mask >> (q - t % q);
          }
          masks[pi][oi] = total;
        }
      }
      vector<int> pows(P);
      for (int(pi) = 0; (pi) < (int)(P); ++(pi)) pows[pi] = pi + 1;
      int ans = 0;
      vector<vector<int>> bits(P);
      for (int(pi) = 0; (pi) < (int)(P); ++(pi)) bits[pi].assign(pows[pi], 0);
      vector<int> zeros(P, 0);
      for (int L = 0, R = 0; L != occurs[a].size(); ++L) {
        for (; R != occurs[a].size() && occurs[a][R] == occurs[a][L] + (R - L);
             ++R) {
          bool ok = true;
          for (int(pi) = 0; (pi) < (int)(P); ++(pi)) {
            long long mask = masks[pi][R];
            if (mask == (1LL << pows[pi]) - 1) continue;
            int z = 0;
            for (int(qi) = 0; (qi) < (int)(pows[pi]); ++(qi)) {
              if ((mask >> qi & 1) == 0) z += bits[pi][qi] == 0;
            }
            if (zeros[pi] + z == pows[pi]) {
              ok = false;
              break;
            }
          }
          if (!ok) break;
          for (int(pi) = 0; (pi) < (int)(P); ++(pi)) {
            long long mask = masks[pi][R];
            if (mask == (1LL << pows[pi]) - 1) continue;
            int z = 0;
            for (int(qi) = 0; (qi) < (int)(pows[pi]); ++(qi)) {
              if ((mask >> qi & 1) == 0) z += ++bits[pi][qi] == 1;
            }
            zeros[pi] += z;
          }
        }
        amax(ans, R - L);
        for (int(pi) = 0; (pi) < (int)(P); ++(pi)) {
          long long mask = masks[pi][L];
          if (mask == (1LL << pows[pi]) - 1) continue;
          int z = 0;
          for (int(qi) = 0; (qi) < (int)(pows[pi]); ++(qi)) {
            if ((mask >> qi & 1) == 0) z += --bits[pi][qi] == 0;
          }
          zeros[pi] -= z;
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
