You are given n sequences. Each sequence consists of positive integers, not exceeding m. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the i-th sequence is ki.

Each second integers in each of the sequences are shifted by one to the left, i.e. integers at positions i > 1 go to positions i - 1, while the first integers becomes the last.

Each second we take the first integer of each sequence and write it down to a new array. Then, for each value x from 1 to m we compute the longest segment of the array consisting of element x only.

The above operation is performed for 10100 seconds. For each integer from 1 to m find out the longest segment found at this time.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of sequences and the maximum integer that can appear in the sequences. 

Then follow n lines providing the sequences. Each of them starts with an integer ki (1 ≤ ki ≤ 40) — the number of integers in the sequence, proceeded by ki positive integers — elements of the sequence. It's guaranteed that all integers in each sequence are pairwise distinct and do not exceed m.

The total length of all sequences doesn't exceed 200 000.

Output

Print m integers, the i-th of them should be equal to the length of the longest segment of the array with all its values equal to i during the first 10100 seconds.

Examples

Input

3 4
3 3 4 1
4 1 3 4 2
3 3 1 4


Output

2
1
3
2


Input

5 5
2 3 1
4 5 1 3 2
4 2 1 3 5
1 3
2 5 3


Output

3
1
4
0
1


Input

4 6
3 4 5 3
2 6 3
2 3 6
3 3 6 5


Output

0
0
2
1
1
2
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXK = 41;
const int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
const int pot[] = {2,  3,  4,  5,  7,  8,  9,  11, 13, 16,
                   17, 19, 23, 25, 27, 29, 31, 32, 37};
const int p[] = {2,  3,  2,  5, 7, 2,  3,  11, 13, 2,
                 17, 19, 23, 5, 3, 29, 31, 2,  37};
int N, M;
int k[MAXN];
int a[MAXN][MAXK];
vector<pair<int, int> > pos[MAXN];
int mat[MAXN][MAXK];
int nxt[MAXN][MAXK];
int diff[MAXN][MAXK];
bool f;
void load() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", k + i);
    for (int j = 0; j < k[i]; j++) scanf("%d", a[i] + j);
  }
}
bool check(int x, int len) {
  int last[MAXK], power[MAXK];
  for (int i = 0; i < 12; i++) last[prime[i]] = -1;
  bool g = f && x == 0 && len == 2;
  if (g) puts("da");
  for (int i = 0; i < 19; i++) {
    int tmp = nxt[x][i];
    if (g) printf("tmp diff %d %d\n", tmp, diff[tmp][i]);
    if (tmp >= x + len) continue;
    if (diff[tmp][i] < x + len) return false;
    int curr = mat[tmp][i];
    if (last[p[i]] != -1 && (curr - last[p[i]]) % power[p[i]]) return false;
    last[p[i]] = curr;
    power[p[i]] = pot[i];
    if (g) printf("pot %d\n", pot[i]);
  }
  return true;
}
int longest(const vector<pair<int, int> > &V) {
  for (int i = 0; i < V.size(); i++)
    if (f) printf("%d %d\n", V[i].first, V[i].second);
  if (f) puts("");
  int sz = V.size();
  vector<int> len, mod;
  for (int i = 0; i < sz; i++) {
    len.push_back(k[V[i].first]);
    mod.push_back(V[i].second);
  }
  if (f) {
    for (int i = 0; i < sz; i++) printf("%d %d\n", mod[i], len[i]);
    puts("");
  }
  for (int i = 0; i < sz; i++)
    for (int j = 0; j < 19; j++)
      if (!(len[i] % pot[j]))
        mat[i][j] = mod[i] % pot[j];
      else
        mat[i][j] = -1;
  for (int j = 0; j < 19; j++) {
    nxt[sz][j] = sz;
    diff[sz][j] = sz;
    mat[sz][j] = -2;
    for (int i = sz - 1; i >= 0; i--) {
      if (mat[i][j] != -1)
        nxt[i][j] = i;
      else
        nxt[i][j] = nxt[i + 1][j];
      if (mat[i][j] == mat[nxt[i + 1][j]][j])
        diff[i][j] = diff[nxt[i + 1][j]][j];
      else
        diff[i][j] = nxt[i + 1][j];
      if (f && i == 1 && j == 0)
        printf("%d %d\n", nxt[i][j], diff[nxt[i][j]][j]);
    }
  }
  if (f) printf("DIFF %d\n", diff[1][0]);
  int res = 0;
  for (int i = 0; i < sz; i++) {
    int lo = 1, hi = sz - i + 1;
    while (lo < hi) {
      int mid = (lo + hi + 1) / 2;
      if (check(i, mid))
        lo = mid;
      else
        hi = mid - 1;
    }
    res = max(res, lo);
  }
  return res;
}
int calc(int x) {
  vector<pair<int, int> > curr;
  int res = 0;
  for (int i = 0; i < pos[x].size(); i++) {
    if (i && pos[x][i].first > pos[x][i - 1].first + 1) {
      res = max(res, longest(curr));
      curr.clear();
    }
    curr.push_back(pos[x][i]);
  }
  res = max(res, longest(curr));
  return res;
}
void solve() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < k[i]; j++) pos[a[i][j]].push_back(pair<int, int>(i, j));
  for (int i = 1; i <= M; i++) printf("%d\n", calc(i));
}
int main() {
  load();
  solve();
  return 0;
}
