#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b) {
    return gcd(b, a % b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct RangeTree {
 private:
  vector<long long> b;
  int kk;

 public:
  RangeTree(const vector<int>& v) {
    int n = int(v.size());
    kk = 1;
    while (kk < n) {
      kk *= 2;
    }
    b.resize(2 * kk + 10, 1);
    for (int i = 0; i < n; ++i) {
      b[i + kk] = v[i];
    }
    for (int i = kk - 1; i >= 1; --i) {
      b[i] = lcm(b[2 * i], b[2 * i + 1]);
    }
  }
  long long getLCM(int L, int R) {
    ;
    L += kk;
    R += kk;
    long long res = 1;
    while (L <= R) {
      if (L % 2 == 1) {
        res = lcm(res, b[L++]);
      }
      if (R % 2 == 0) {
        res = lcm(res, b[R--]);
      }
      L /= 2, R /= 2;
    };
    return res;
  }
};
long long sum(long long x, long long y, long long MOD) {
  if ((x += y) >= MOD) {
    x -= MOD;
  }
  return x;
}
long long product(long long x, long long y, long long MOD) {
  long long res = 0;
  while (y) {
    if (y & 1) {
      res = sum(res, x, MOD);
    }
    x = sum(x, x, MOD);
    y /= 2;
  }
  return res;
}
long long inverse(long long x, long long MOD) {
  long long a = x;
  long long b = MOD;
  long long p = 1, q = 0;
  long long r = 0, s = 1;
  while (a && b) {
    if (a >= b) {
      long long k = a / b;
      a %= b;
      p -= r * k;
      q -= s * k;
    } else {
      long long k = b / a;
      b %= a;
      r -= p * k;
      s -= q * k;
    }
  }
  long long res;
  if (a) {
    assert(a == 1);
    res = p;
  } else {
    assert(b == 1);
    res = r;
  }
  res %= MOD;
  if (res < 0) {
    res += MOD;
  };
  assert(product(res, x, MOD) == 1);
  return res;
}
bool canExpand(long long& totMod, long long& totRem, long long newMod,
               long long newRem) {
  ;
  long long D = gcd(totMod, newMod);
  if (totRem % D != newRem % D) {
    ;
    return false;
  }
  long long mod1 = totMod;
  long long rem1 = totRem;
  long long mod2 = newMod;
  long long rem2 = newRem;
  {
    long long b = mod1 / D;
    long long c = mod2 / D;
    long long r = ((rem2 - rem1) / D) % c;
    if (r < 0) {
      r += c;
    }
    long long k = (r == 0 ? 0 : product(inverse(b, c), r, c));
    totRem = k * mod1 + rem1;
    totMod = b * c * D;
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<pair<int, int> > > pos(m);
  vector<int> k(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &k[i]);
    for (int j = 0; j < k[i]; ++j) {
      int a;
      scanf("%d", &a);
      --a;
      pos[a].push_back(pair<int, int>(i, j));
    }
  }
  RangeTree tree(k);
  vector<int> res(m, 0);
  for (int i = 0; i < m; ++i) {
    int L = -2, R = -2;
    long long totMod = 1, totRem = 0;
    for (int j = 0; j < (int)pos[i].size(); ++j) {
      int curPos = pos[i][j].first;
      long long curRem = pos[i][j].second;
      long long curMod = k[curPos];
      if (R + 1 < pos[i][j].first) {
        L = R = curPos;
        totMod = curMod;
        totRem = curRem;
      } else {
        while (!canExpand(totMod, totRem, curMod, curRem)) {
          ++L;
          totMod = tree.getLCM(L, R);
          totRem %= totMod;
        }
        ++R;
      }
      res[i] = max(res[i], R - L + 1);
    }
  }
  for (int i = 0; i < m; ++i) {
    printf("%d\n", res[i]);
  }
  return 0;
}
