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;
long long gc(long long v1, long long v2) {
  if (v1 == 0 || v2 == 0) return v1 + v2;
  if (v1 > v2) swap(v1, v2);
  return gc(v1, v2 % v1);
}
namespace SUM_ver {
pair<long long, long long> INIT = pair<long long, long long>(-1, -1);
pair<long long, long long> impo = pair<long long, long long>(0, 0);
pair<long long, long long> node_calc(pair<long long, long long> n1,
                                     pair<long long, long long> n2) {
  if (n1 == INIT) return n2;
  if (n2 == INIT) return n1;
  if (n1.first == 0 || n2.first == 0) return impo;
  pair<long long, long long> ret;
  ret.first = (n1.first / gc(n1.first, n2.first)) * n2.first;
  long long o1 = ret.first / n1.first;
  long long o2 = ret.first / n2.first;
  if (o2 < o1) swap(n1, n2);
  long long now = n1.second;
  for (long long i = 0; i < ret.first; i += n1.first) {
    if ((i + now) % n2.first == n2.second) {
      ret.second = i + now;
      return ret;
    }
  }
  return impo;
}
}  // namespace SUM_ver
using namespace SUM_ver;
struct segment_tree {
  int tree_n;
  vector<pair<long long, long long> > tree;
  void init(vector<pair<long long, long long> >& v) {
    tree.resize(4 * v.size() + 1);
    for (int i = 0; i < tree.size(); i++) tree[i] = INIT;
    tree_n = 1;
    while (tree_n < v.size()) tree_n <<= 1;
    for (int i = 0; i < v.size(); i++) tree[tree_n + i - 1] = v[i];
    for (int i = tree_n - 2; i >= 0; i--)
      tree[i] = node_calc(tree[i * 2 + 1], tree[i * 2 + 2]);
  }
  void init(int vn) {
    vector<pair<long long, long long> > v(vn + 1, INIT);
    init(v);
  }
  void recalc(int position) {
    while (position != 0) {
      position = (position - 1) >> 1;
      tree[position] =
          node_calc(tree[position * 2 + 1], tree[position * 2 + 2]);
    }
  }
  void update_push(int position, pair<long long, long long> v) {
    position += tree_n - 1;
    tree[position] = v;
    recalc(position);
  }
  void update_calc(int position, pair<long long, long long> v) {
    position += tree_n - 1;
    tree[position] = node_calc(tree[position], v);
    recalc(position);
  }
  pair<long long, long long> query(int a, int b, int idx, int left, int right) {
    if (right <= a || left >= b) return INIT;
    if (left >= a && right <= b) return tree[idx];
    int mid = (left + right) / 2;
    return node_calc(query(a, b, idx * 2 + 1, left, mid),
                     query(a, b, idx * 2 + 2, mid, right));
  }
  pair<long long, long long> query(int a, int b) {
    return query(a, b, 0, 0, tree_n);
  }
} smtree;
const int N = 100000;
int n, m;
int ans;
vector<pair<int, pair<long long, long long> > > a[N + 5];
vector<pair<long long, long long> > v;
int get_ans() {
  int ret = 0;
  smtree.init(v.size() + 1);
  int j = 0;
  for (int i = 0; i < v.size(); i++) {
    smtree.update_push(i, v[i]);
    while (smtree.query(j, i + 1) == impo && j < i) j++;
    ret = max(ret, i - j + 1);
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int op;
    scanf("%d", &op);
    for (int j = 0; j < op; j++) {
      int po;
      scanf("%d", &po);
      a[po].push_back(pair<int, pair<long long, long long> >(
          i, pair<long long, long long>(op, j)));
    }
  }
  for (int i = 1; i <= m; i++) {
    ans = 0;
    int st = 0;
    for (int j = 0; j < a[i].size(); j++) {
      if (j + 1 == a[i].size() || a[i][j].first + 1 != a[i][j + 1].first) {
        v.clear();
        for (int k = st; k <= j; k++) v.push_back(a[i][k].second);
        ans = max(ans, get_ans());
        st = j + 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
