#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
const int maxk = 41;
int n, m, val[maxk][maxk], cnt[maxk], brk;
vector<pair<int, pair<int, int> > > idxs[maxn];
vector<int> divs[maxk];
void update(int k, int v, int delta) {
  for (auto d : divs[k]) {
    brk -= cnt[d] > 1;
    cnt[d] -= val[d][v % d] > 0;
    val[d][v % d] += delta;
    cnt[d] += val[d][v % d] > 0;
    brk += cnt[d] > 1;
  }
}
int calc(vector<pair<int, pair<int, int> > > &idx, int l, int r) {
  int mx = 0;
  int ptr = l;
  for (int i = l; i < r; ++i) {
    while (ptr < r && brk == 0) {
      mx = max(mx, ptr - i);
      update(idx[ptr].second.first, idx[ptr].second.second, 1);
      ++ptr;
    }
    if (brk == 0) mx = max(mx, ptr - i);
    update(idx[i].second.first, idx[i].second.second, -1);
  }
  return mx;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 1; i < maxk; ++i) {
    for (int j = i; j < maxk; j += i) divs[j].emplace_back(i);
  }
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      --x;
      idxs[x].push_back({i, {k, j}});
    }
  }
  for (int x = 0; x < m; ++x) {
    int sz = idxs[x].size();
    int mx = 0;
    int i = 0;
    while (i < sz) {
      int j = i + 1;
      while (j < sz && idxs[x][j].first == idxs[x][j - 1].first + 1) ++j;
      mx = max(mx, calc(idxs[x], i, j));
      i = j;
    }
    cout << mx << '\n';
  }
}
