#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const long long inf = 314000000;
int n, m;
vector<int> a[maxn], d[maxn];
int deg[maxn], bel[maxn], pay[maxn];
int sta[maxn], dpl[maxn], dpr[maxn], leg[maxn];
struct data {
  int x, y;
  data() {}
  data(int x, int y) : x(x), y(y) {}
  bool operator<(const data &t) const { return y > t.y; }
};
vector<data> b[maxn];
void DP(int x) {
  if (sta[x] == 2) return;
  if (sta[x] == 1) {
    sta[x] = 2;
    dpr[x] = -2;
    return;
  }
  sta[x] = 1;
  int i, j, y, z, c;
  for (i = 0; i < (int)d[x].size(); i++) {
    y = d[x][i], c = 0;
    if (!deg[y]) {
      for (j = 0; j < (int)a[y].size(); j++) {
        z = a[y][j];
        DP(z);
        if (dpr[z] == -2) {
          sta[x] = 2, dpr[x] = -2;
          return;
        }
        c = min(inf, (long long)c + dpr[z]);
      }
      dpr[x] = max(c, dpr[x]);
    }
  }
  sta[x] = 2;
}
void check() {
  int i, tp, tmp;
  data p;
  priority_queue<data> hp;
  hp.push(data(0, 1));
  for (i = 1; i <= n; i++) dpl[i] = 314000001;
  dpl[0] = 1;
  while (hp.size()) {
    tp = hp.top().x;
    hp.pop();
    if (leg[tp]) continue;
    leg[tp] = 1;
    for (i = 0; i < (int)b[tp].size(); i++) {
      p = b[tp][i];
      pay[p.x] = min(inf, 1LL * p.y * dpl[tp] + pay[p.x]);
      if ((--deg[p.x]) == 0) {
        tmp = bel[p.x];
        if (dpl[tmp] > pay[p.x]) hp.push(data(tmp, dpl[tmp] = pay[p.x]));
      }
    }
  }
}
int main() {
  int i, j, x, y, z, cnt;
  scanf("%d%d", &m, &n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    bel[i] = x;
    vector<int> &a = ::a[i];
    for (j = 1; j <= y; j++) {
      scanf("%d", &z);
      if (z == -1) z = 0;
      a.push_back(z);
    }
    sort(a.begin(), a.end());
    for (cnt = j = 0, z = a.size() - 1; j <= z; j++) {
      ++cnt;
      if (j == z || a[j + 1] != a[j]) {
        deg[i]++;
        b[a[j]].push_back(data(i, cnt));
        cnt = 0;
      }
    }
    d[x].push_back(i);
  }
  check();
  dpr[0] = 1;
  sta[0] = 2;
  for (i = 1; i <= n; i++) {
    if (leg[i])
      DP(i), printf("%d %d\n", dpl[i], dpr[i]);
    else
      puts("-1 -1");
  }
  return 0;
}
