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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int int_inf = 0x3f3f3f3f;
const long long ll_inf = 0x3f3f3f3f3f3f3f3f;
const int INT_INF = (int)((1ll << 31) - 1);
const double double_inf = 1e30;
const double eps = 1e-14;
inline int readint() {
  int x;
  scanf("%d", &x);
  return x;
}
inline int readstr(char *s) {
  scanf("%s", s);
  return strlen(s);
}
class cmpt {
 public:
  bool operator()(const int &x, const int &y) const { return x > y; }
};
int Rand(int x, int o) {
  if (!x) return 0;
  int tem = (int)((double)rand() / RAND_MAX * x) % x;
  return o ? tem + 1 : tem;
}
long long ll_rand(long long x, int o) {
  if (!x) return 0;
  long long tem = (long long)((double)rand() / RAND_MAX * x) % x;
  return o ? tem + 1 : tem;
}
void data_gen() {
  int kases = 1;
  printf("%d\n", kases);
  while (kases--) {
    long long sz = 5;
    printf("%d\n", sz);
    for (int i = (1); i <= (sz); i++) {
      int x = Rand(1000, 1);
      int y = Rand(1000, 1);
      int z = Rand(10000, 1);
      printf("%d %d %d\n", x, y, z);
    }
    putchar('\n');
  }
}
const int maxn = 1e5 + 10;
int n, m;
vector<int> a[maxn];
int sz[maxn];
vector<std ::pair<int, int> > b[maxn];
int ans[maxn];
int len;
std ::pair<int, int> buf[maxn];
struct Seg {
  int l, r;
  pair<long long, long long> tem;
} seg[maxn << 2];
long long multi(long long x, long long y, long long mod) {
  y = (y % mod + mod) % mod, x = (x % mod + mod) % mod;
  long long ans = 0;
  while (y) {
    if (x <= 1e7 && y <= 1e7) {
      return (ans + x * y) % mod;
    }
    if (y & 1) ans = (ans + x) % mod;
    y >>= 1;
    x = (x + x) % mod;
  }
  return ans;
}
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long egcd(long long a, long long b, long long &x, long long &y,
               long long mod) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long d = egcd(b, a % b, y, x, mod);
  y -= multi(a / b, x, mod);
  y = (y % mod + mod) % mod;
  return d;
}
pair<long long, long long> sub(pair<long long, long long> lhs,
                               pair<long long, long long> rhs) {
  if (lhs.second == -1 || rhs.second == -1) return std ::make_pair(0, -1);
  long long d = gcd(lhs.second, rhs.second);
  long long delta = lhs.first - rhs.first;
  if (delta % d) return std ::make_pair(0, -1);
  long long x, y;
  long long P = lhs.second / d * rhs.second;
  egcd(lhs.second / d, rhs.second / d, x, y, P);
  long long ratio = delta / d;
  long long v = (rhs.first + multi(multi(ratio, y, P), rhs.second, P)) % P;
  return std ::make_pair((v + P) % P, P);
}
void build(int u, int l, int r) {
  seg[u].l = l, seg[u].r = r;
  if (r - l < 2) {
    seg[u].tem = buf[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((u << 1), l, mid);
  build((u << 1 | 1), mid, r);
  seg[u].tem = sub(seg[(u << 1)].tem, seg[(u << 1 | 1)].tem);
}
pair<long long, long long> okay(int u, int l, int r, int L, int R) {
  if (l == L && R == r) return seg[u].tem;
  int mid = (l + r) >> 1;
  if (R <= mid)
    return okay((u << 1), l, mid, L, R);
  else if (L >= mid)
    return okay((u << 1 | 1), mid, r, L, R);
  pair<long long, long long> lhs = okay((u << 1), l, mid, L, mid),
                             rhs = okay((u << 1 | 1), mid, r, mid, R);
  return sub(lhs, rhs);
}
bool check(int u, int length, int len) {
  for (int i = (1); i <= (len - length + 1); i++) {
    if (okay(1, 1, len + 1, i, i + length).second != -1) return true;
  }
  return false;
}
int cal(int u) {
  int p = 0, tot = b[u].size();
  int tans = 0;
  while (p < tot) {
    int q = p;
    len = 0;
    buf[++len] = std ::make_pair(b[u][p].second, sz[b[u][p].first]);
    while (q + 1 < tot && b[u][q + 1].first == b[u][q].first + 1) {
      ++q;
      buf[++len] = std ::make_pair(b[u][q].second, sz[b[u][q].first]);
    }
    build(1, 1, len + 1);
    int l = 1, r = len + 1;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (check(u, mid, len))
        l = mid;
      else
        r = mid;
    }
    tans = (((tans)) > ((l)) ? ((tans)) : ((l)));
    p = q + 1;
  }
  return tans;
}
int main() {
  int debug = 0;
  if (debug) freopen("in.txt", "r", stdin);
  while (~scanf("%d%d", &n, &m)) {
    for (int i = (1); i <= (n); i++) a[i].clear();
    for (int i = (1); i <= (m); i++) b[i].clear();
    for (int i = (1); i <= (n); i++) {
      sz[i] = readint();
      for (int j = (1); j <= (sz[i]); j++) {
        int x = readint();
        a[i].push_back(x);
        b[x].push_back(std ::make_pair(i, j - 1));
      }
    }
    for (int i = (1); i <= (m); i++) ans[i] = cal(i);
    for (int i = (1); i <= (m); i++) printf("%d\n", ans[i]);
  }
  return 0;
}
