#include <bits/stdc++.h>
using namespace std;
const int MX = 100005, INF = 1000000000, mod = 314000000;
const long long int LINF = 1000000000000000000ll;
const double eps = 1e-9;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n, m;
int a[MX], c[MX], d[MX], e[MX];
vector<int> t[MX], u[MX], b[MX];
bool can[MX], ok[MX], used[MX];
int mn[MX], mx[MX];
int main() {
  int x, y, z;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    t[--x].push_back(i);
    for (int j = 0; j < y; j++) {
      scanf("%d", &z);
      if (z == -1)
        c[i]++;
      else {
        b[i].push_back(--z);
        u[z].push_back(i);
      }
    }
    d[i] = b[i].size();
    e[i] = x;
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    bool bl = false;
    for (int j = 0; j < t[i].size(); j++)
      if (!d[t[i][j]]) bl = true;
    if (bl) q.push(i);
  }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    if (can[x]) continue;
    can[x] = true;
    for (int i = 0; i < u[x].size(); i++) {
      d[u[x][i]]--;
      if (!d[u[x][i]]) q.push(e[u[x][i]]);
    }
  }
  for (int i = 0; i < m; i++) {
    x = e[i];
    d[i] = b[i].size();
    if (!can[x]) continue;
    bool bl = true;
    for (int j = 0; j < b[i].size(); j++) {
      if (!can[b[i][j]]) bl = false;
    }
    if (bl) ok[i] = true;
  }
  for (int i = 0; i < n; i++) {
    if (!can[i]) continue;
    bool bl = true;
    mn[i] = mod;
    mx[i] = 0;
    a[i] = 0;
    for (int j = 0; j < t[i].size(); j++) {
      x = t[i][j];
      if (ok[x] && b[x].size()) {
        bl = false;
        a[i]++;
      }
    }
    if (bl) q.push(i);
  }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    if (used[x]) continue;
    used[x] = true;
    if (!can[x]) continue;
    int dw = mod, up = 0;
    int dwx, upx;
    for (int i = 0; i < t[x].size(); i++) {
      y = t[x][i];
      if (!ok[y]) continue;
      dwx = upx = c[y];
      for (int j = 0; j < b[y].size(); j++) {
        dwx += mn[b[y][j]];
        upx += mx[b[y][j]];
        dwx = min(dwx, mod);
        upx = min(upx, mod);
      }
      dw = min(dw, dwx);
      up = max(up, upx);
    }
    mn[x] = dw;
    mx[x] = min(mod, up);
    for (int i = 0; i < u[x].size(); i++) {
      if (!ok[u[x][i]]) continue;
      d[u[x][i]]--;
      if (!d[u[x][i]]) {
        y = e[u[x][i]];
        a[y]--;
        if (!a[y]) q.push(y);
      }
    }
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  for (int i = 0; i < n; i++) {
    if (!can[i] || used[i]) continue;
    mx[i] = -2;
    for (int j = 0; j < t[i].size(); j++) {
      x = t[i][j];
      if (ok[x] && !d[x]) {
        z = c[x];
        for (int k = 0; k < b[x].size(); k++) {
          z += mn[b[x][k]];
          z = min(z, mod);
        }
        mn[i] = min(mn[i], z);
      }
    }
    pq.push(pair<int, int>(mn[i], i));
  }
  while (!pq.empty()) {
    x = pq.top().second;
    pq.pop();
    if (used[x]) continue;
    used[x] = true;
    if (!can[x]) continue;
    for (int i = 0; i < u[x].size(); i++) {
      z = u[x][i];
      if (!ok[z]) continue;
      d[z]--;
      if (!d[z]) {
        y = e[z];
        int cnt = c[z];
        for (int j = 0; j < b[z].size(); j++) {
          cnt += mn[b[z][j]];
          cnt = min(cnt, mod);
        }
        if (cnt < mn[y]) {
          mn[y] = cnt;
          pq.push(pair<int, int>(cnt, y));
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (can[i]) {
      printf("%d %d\n", mn[i], mx[i]);
    } else {
      printf("-1 -1\n");
    }
  }
  return 0;
}
