#include <bits/stdc++.h>
using namespace std;
int m, n, of[(120000)];
vector<int> rl[(120000)], rls[(120000)], has[(120000)];
int ty[(120000)], cnt[(120000)];
int vis[(120000)];
int is[(120000)];
long long amin[(120000)], amax[(120000)];
set<pair<long long, int> > que;
void fix(int k, long long num) {
  if (amin[k] < num) return;
  amin[k] = num;
  for (int i = 0; i < (int)(has[k].size()); i++) {
    const int t = has[k][i];
    cnt[t]++;
    if (ty[t] == cnt[t]) {
      long long s = 0;
      for (int i = 0; i < (int)(rl[t].size()); i++) {
        if (rl[t][i] == -1)
          s++;
        else
          s += amin[rl[t][i]];
        if (s > (314000000LL)) s = (314000000LL);
      }
      const int o = of[t];
      if (!is[o] || amin[o] > s) {
        if (que.count(make_pair(amin[o], o))) {
          que.erase(make_pair(amin[o], o));
        }
        is[o] = 1;
        amin[o] = s;
        que.insert(make_pair(amin[o], o));
      }
    }
  }
}
void solvea() {
  for (int i = 0; i < (int)(m); i++)
    if (rl[i].back() == -1) {
      is[of[i]] = 1;
      amin[of[i]] = rl[i].size();
      que.insert(make_pair((long long)rl[i].size(), of[i]));
    }
  while (!que.empty()) {
    pair<long long, int> v = *que.begin();
    que.erase(que.begin());
    fix(v.second, v.first);
  }
}
void rec(int at) {
  if (vis[at]) return;
  vis[at] = 1;
  long long ans = 0;
  for (int k = 0; k < (int)(rls[at].size()); k++) {
    long long sum = 0;
    for (int i = 0; i < (int)(rl[rls[at][k]].size()); i++) {
      const int x = rl[rls[at][k]][i];
      if (x == -1)
        sum++;
      else {
        if (is[x] == 0) {
          sum = -1;
          break;
        }
        rec(x);
        sum += amax[x];
      }
      sum = min(sum, (1LL << 50));
      if (sum < (1LL << 50)) sum = min(sum, (314000000LL));
    }
    if (sum != -1) ans = max(ans, sum);
  }
  amax[at] = ans;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < (int)(m); i++) {
    int L;
    scanf("%d%d", of + i, &L);
    of[i]--;
    rls[of[i]].push_back(i);
    vector<int> v;
    for (int _ = 0; _ < (int)(L); _++) {
      int a;
      scanf("%d", &a);
      if (a > 0) {
        a--;
        if (has[a].empty() || has[a].back() != i) has[a].push_back(i);
      }
      v.push_back(a);
    }
    sort(v.begin(), v.end());
    rl[i] = v;
    v.erase(unique(v.begin(), v.end()), v.end());
    ty[i] = v.size() - 1;
  }
  solvea();
  for (int i = 0; i < (int)(n); i++) amax[i] = (1LL << 50);
  for (int i = 0; i < (int)(n); i++) rec(i);
  for (int i = 0; i < (int)(n); i++) {
    if (amax[i] == (1LL << 50)) amax[i] = -2;
    if (!is[i])
      cout << -1 << ' ' << -1 << endl;
    else
      cout << amin[i] << ' ' << amax[i] << endl;
  }
  return 0;
}
