#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
struct node {
  int p, x, y;
};
vector<node> g[N];
vector<int> f[45];
struct array {
  int a[45], mx, mx2;
  int get(int x) {
    if (mx == a[x]) return mx2;
    return mx;
  }
  void change(int x, int y) {
    mx2 = get(x);
    mx = y;
    a[x] = y;
  }
} last[45];
inline int solve(int x) {
  int m = g[x].size(), ans = 0;
  if (!m) return 0;
  for (int i = (0); i < (m); i++) {
    int l = i, r = i;
    while (r < m - 1 && g[x][r + 1].p == g[x][r].p + 1) r++;
    int pre = l - 1;
    for (int j = (l); j <= (r); j++) {
      int k = g[x][j].x, y = g[x][j].y;
      for (int t = (0); t < (f[k].size()); t++) {
        int p = f[k][t], e = y % p;
        pre = max(pre, last[p].get(e));
        last[p].change(e, j);
      }
      ans = max(ans, j - pre);
    }
    for (int j = (l); j <= (r); j++) {
      int k = g[x][j].x, y = g[x][j].y;
      for (int t = (0); t < (f[k].size()); t++) {
        int p = f[k][t];
        last[p].change(y % p, -1);
      }
    }
    i = r;
  }
  return ans;
}
int main() {
  for (int i = (1); i <= (40); i++) {
    bool isok = 0;
    for (int j = (2); j <= (i); j++) {
      if (i % j != 0) continue;
      int t = i;
      while (t % j == 0) t /= j;
      if (t == 1) isok = 1;
      break;
    }
    if (!isok && i != 1) continue;
    for (int j = i; j <= 40; j += i) f[j].push_back(i);
  }
  scanf("%d%d", &n, &m);
  memset(last, -1, sizeof(last));
  for (int i = (1); i <= (n); i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back((node){i, k, j});
    }
  }
  for (int i = (1); i <= (m); i++) printf("%d\n", solve(i));
  return 0;
}
