#include <bits/stdc++.h>
using namespace std;
const int MN = 201234, MX = 42;
int dp[MX][MX], k[MN];
vector<pair<int, int> > all[MN], gd[MN];
void get(vector<pair<int, int> > &vec, int now, int x) {
  for (auto &p : vec) {
    int v = p.first, y = p.second;
    int mark[MX] = {};
    for (int i = 0; i < v; i += y) mark[(i + now) % v] = true;
    for (int i = 0; i < v; i++)
      if (!mark[i]) dp[v][i] = x;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", k + i);
    for (int j = 0; j < k[i]; j++) {
      int x;
      scanf("%d", &x);
      all[x].push_back({i, j});
    }
  }
  for (int iii = 0; iii < n; iii++) {
    int x = k[iii];
    for (int i = 2; i <= x; i++) {
      if (x % i == 0) {
        int ii = 1;
        while (x % i == 0) {
          ii *= i;
          x /= i;
        }
        int ans = ii;
        while (ans < MX) ans *= i;
        ans /= i;
        gd[iii].push_back({ans, ii});
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int i = 0; i < MX; i++)
      for (int j = 0; j < MX; j++) dp[i][j] = -1;
    sort(all[i].begin(), all[i].end());
    auto &vec = all[i];
    int bad = -1, lst = -1;
    int ans = 0;
    for (int j = 0; j < vec.size(); j++) {
      int now = vec[j].second;
      int x = vec[j].first;
      if (lst != x - 1) bad = x - 1;
      lst = x;
      for (auto &p : gd[x]) {
        int v = p.first, y = p.second;
        int mn = MN;
        for (int i = 0; i < v; i += y) mn = min(mn, dp[v][(now + i) % v]);
        bad = max(bad, mn);
      }
      ans = max(ans, x - bad);
      get(gd[x], now, x);
    }
    cout << ans << '\n';
  }
}
