#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, c[N], a[N][41], hd[N], nx[N * 41], t[N], f[N], k[N], b[N], ans;
vector<pair<int, int> > V[N];
inline void read(int &i) {
  i = 0;
  char c = getchar();
  bool j = 0;
  for (; !isdigit(c); c = getchar())
    if (c == '-') j = 1;
  for (; isdigit(c); c = getchar()) i = (i << 1) + (i << 3) + c - '0';
  i = j ? -i : i;
}
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
inline void calc(int n) {
  for (int i = 1, j = 1; i <= n; ++i) {
    while (j <= n) {
      bool fg = 1;
      for (int l = 1; l <= 40; ++l)
        if (t[l]) {
          int g = gcd(k[j], l);
          if ((b[j] - f[l]) % g) {
            fg = 0;
            break;
          }
        }
      if (fg) {
        t[k[j]]++;
        f[k[j]] = b[j];
        j++;
      } else
        break;
    }
    ans = max(ans, j - i);
    t[k[i]]--;
  }
}
inline void work(vector<pair<int, int> > &V) {
  ans = 0;
  int n = V.size();
  for (int i = 0; i < n;) {
    int j = i;
    while (j + 1 < n && V[j + 1].first == V[j].first + 1) j++;
    if (j - i + 1 <= ans) {
      i = j + 1;
      continue;
    }
    for (int l = i; l <= j; ++l)
      k[l - i + 1] = c[V[l].first], b[l - i + 1] = V[l].second;
    calc(j - i + 1);
    i = j + 1;
  }
  printf("%d\n", ans);
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    read(c[i]);
    for (int j = 1; j <= c[i]; ++j)
      read(a[i][j]), V[a[i][j]].push_back(make_pair(i, j - 1));
  }
  for (int i = 1; i <= m; ++i) work(V[i]);
  return 0;
}
