#include <bits/stdc++.h>
using namespace std;
vector<int> l[110000], to[110000], from[110000];
int own[110000], out[110000];
int mi[110000], ma[110000];
bool vis[110000];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
int calc_mi(int x) {
  int ret = 0;
  for (vector<int>::iterator it = l[x].begin(); it != l[x].end(); it++) {
    if (*it == -1)
      ret++;
    else
      ret += mi[*it];
    ret = min(ret, 314000000);
  }
  return ret;
}
int calc_ma(int x);
int getma(int x) {
  if (vis[x]) return -2;
  if (mi[x] == -1) return -1;
  if (ma[x] != -1) return ma[x];
  ma[x] = 0;
  vis[x] = 1;
  for (vector<int>::iterator it = to[x].begin(); it != to[x].end(); it++) {
    int temp = calc_ma(*it);
    if (temp == -1) continue;
    if (temp == -2) return ma[x] = -2;
    ma[x] = max(ma[x], temp);
  }
  vis[x] = 0;
  return ma[x];
}
int calc_ma(int x) {
  int ret = 0, temp;
  for (vector<int>::iterator it = l[x].begin(); it != l[x].end(); it++) {
    if (*it == -1) {
      if (ret != -2) ret++;
    } else {
      temp = getma(*it);
      if (temp == -1)
        return -1;
      else if (temp == -2)
        ret = -2;
      else if (ret != -2)
        ret += temp;
    }
    ret = min(ret, 314000000);
  }
  return ret;
}
int main() {
  int n, m, i, j, k, x, y;
  scanf("%d%d", &m, &n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &k);
    own[i] = x;
    to[x].push_back(i);
    for (j = 1; j <= k; j++) {
      scanf("%d", &y);
      l[i].push_back(y);
      if (y != -1) from[y].push_back(i), out[i]++;
    }
  }
  memset(mi, -1, sizeof(mi));
  memset(ma, -1, sizeof(ma));
  for (i = 1; i <= m; i++) {
    if (out[i] == 0) {
      if (mi[own[i]] == -1) mi[own[i]] = 314000000;
      mi[own[i]] = min(calc_mi(i), mi[own[i]]);
      q.push(pair<int, int>(mi[own[i]], own[i]));
    }
  }
  while (!q.empty()) {
    x = q.top().second, q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (vector<int>::iterator it = from[x].begin(); it != from[x].end();
         it++) {
      out[*it]--;
      if (out[*it] == 0) {
        if (mi[own[*it]] == -1) mi[own[*it]] = 314000000;
        mi[own[*it]] = min(calc_mi(*it), mi[own[*it]]);
        q.push(pair<int, int>(mi[own[*it]], own[*it]));
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++) printf("%d %d\n", mi[i], getma(i));
  return 0;
}
