#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b) {       long long t = b;       b = a % b;       a = t;     }     return a;   }   long long mul(long long a, long long b, long long m) {     long long q = (long double)a * (long double)b / (long double)m;     long long r = a * b - q * m;     return (r + 5 * m) % m;   }   long long extendedEuclides(long long a, long long b, long long &x,                              long long &y) {     long long xx = y = 0;     long long yy = x = 1;     while (b) {       long long q = a / b;       long long t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   pair<long long, long long> chineseRemainder(long long x, long long y,                                               long long a, long long b) {     if (a == -1 || b == -1 || x == -1 || y == -1) return make_pair(0, -1);     long long s, t;     long long d = extendedEuclides(x, y, s, t);     if (a % d != b % d) return make_pair(0, -1);     long long mod = x * (y / d);     return make_pair((a + mul(mul(x, s, mod), (b - a) / d, mod) + 5 * mod) % mod,                      x * (y / d));   }   pair<long long, long long> seg[801000];   pair<long long, long long> arr[100100];   void build(int l, int r, int pos) {     if (l == r) {       seg[pos] = arr[l];       return;     }     int m = (l + r) / 2;     build(l, m, 2 * pos + 1);     build(1 + m, r, 2 * pos + 2);     seg[pos] = chineseRemainder(seg[2 * pos + 1].second, seg[2 * pos + 2].second,                                 seg[2 * pos + 1].first, seg[2 * pos + 2].first);   }   pair<long long, long long> qry(int l, int r, int pos, int ql, int qr) {     if (qr >= r && ql <= l) return seg[pos];     if (qr < l || ql > r) return make_pair(0, 1);     pair<long long, long long> pr, pl;     pl = qry(l, (l + r) / 2, 2 * pos + 1, ql, qr);     pr = qry((l + r) / 2 + 1, r, 2 * pos + 2, ql, qr);     return chineseRemainder(pl.second, pr.second, pl.first, pr.first);   }   vector<pair<long long, long long> > arrs[100100];   int ans[100100];   int kss[100100];   int solve(int k) {     build(0, k - 1, 0);     int l = 0, r = 0, mxm = 1;     while (l < k && r < k) {       if (qry(0, k - 1, 0, l, r).second != -1) mxm = max(mxm, r - l + 1);       if (r == k - 1)         l++;       else if (qry(0, k - 1, 0, l, r).second != -1)         r++;       else         l++;       if (qry(0, k - 1, 0, l, r).second != -1) mxm = max(mxm, r - l + 1);     }     r = k - 1;     while (l < k) {       if (qry(0, k - 1, 0, l, r).second != -1) mxm = max(mxm, r - l + 1);       l++;     }     return mxm;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> kss[i];       for (int j = 0; j < kss[i]; j++) {         int a;         cin >> a;         arrs[a].push_back(make_pair(j, i));       }     }     int i = 1;     while (i <= m) {       if (arrs[i].size() == 0) {         cout << 0 << endl;         i++;         continue;       }       pair<int, int> last = arrs[i][0];       int j = 0, h = 1;       arr[0] = make_pair(arrs[i][0].first, kss[arrs[i][0].second]);       while (j < arrs[i].size()) {         j++;         if (j == arrs[i].size() ||             arrs[i][j].second != arrs[i][j - 1].second + 1) {           ans[i] = max(ans[i], solve(h));           h = 0;           if (j != arrs[i].size())             arr[h++] = make_pair(arrs[i][j].first, kss[arrs[i][j].second]);         } else {           arr[h++] = make_pair(arrs[i][j].first, kss[arrs[i][j].second]);         }       }       cout << ans[i] << endl;       i++;     }   }