#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
const int mod = 314000000;
vector<pair<int, int> > g[2 * maxn], gr[2 * maxn];
int deg[2 * maxn], mi[2 * maxn], sum[2 * maxn], ma[2 * maxn];
int used[2 * maxn], n;
int dfs(int v) {
  used[v] = 1;
  if (v < n) {
    for (int i = 0; i < (int)(gr[v]).size(); i++) {
      int to = gr[v][i].first;
      int cnt = gr[v][i].second;
      if (mi[to] == -1) continue;
      if (used[to] == 1) {
        ma[v] = -2;
        return -2;
      } else if (used[to] == 2) {
        ma[v] = max(ma[v], min(mod, ma[to] + cnt));
      } else {
        int ret = dfs(to);
        if (ret == -2) {
          ma[v] = -2;
          return -2;
        }
        ma[v] = max(ma[v], min(mod, ma[to] + cnt));
      }
    }
  } else {
    int sum = 0;
    for (int i = 0; i < (int)(gr[v]).size(); i++) {
      int to = gr[v][i].first;
      int cnt = gr[v][i].second;
      if (used[to] == 1) {
        ma[v] = -2;
        return -2;
      } else if (used[to] == 2) {
        sum += ma[to];
        sum = min(sum, mod);
      } else {
        int ret = dfs(to);
        if (ret == -2) {
          ma[v] = -2;
          return -2;
        }
        sum += ret + cnt;
        sum = min(sum, mod);
      }
    }
    ma[v] = sum;
  }
  used[v] = 2;
  return ma[v];
}
int main() {
  int m;
  cin >> m >> n;
  for (int i = 0; i < n; i++) {
    deg[i] = 1;
    mi[i] = -1;
    ma[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    int cnt = 0;
    for (int j = 0; j < y; j++) {
      int z;
      scanf("%d", &z);
      if (z == -1) {
        cnt++;
      } else {
        --z;
        g[z].push_back(make_pair(n + i, 0));
        gr[n + i].push_back(make_pair(z, 0));
      }
    }
    deg[n + i] = y - cnt;
    g[n + i].push_back(make_pair(x, cnt));
    gr[x].push_back(make_pair(n + i, cnt));
  }
  priority_queue<pair<int, int> > q;
  for (int i = 0; i < n + m; i++) {
    if (deg[i] == 0) {
      mi[i] = 0;
      q.push(make_pair(-mi[i], i));
    } else {
      mi[i] = -1;
    }
  }
  while (!q.empty()) {
    int MI = -q.top().first;
    int v = q.top().second;
    q.pop();
    if (mi[v] < MI) continue;
    if (v < n) {
      for (int i = 0; i < (int)(g[v]).size(); i++) {
        int to = g[v][i].first;
        int cnt = g[v][i].second;
        sum[to] += cnt + mi[v];
        sum[to] = min(sum[to], mod);
        deg[to]--;
        if (deg[to] == 0) {
          mi[to] = sum[to];
          q.push(make_pair(-mi[to], to));
        }
      }
    } else {
      for (int i = 0; i < (int)(g[v]).size(); i++) {
        int to = g[v][i].first;
        int cnt = g[v][i].second;
        if (mi[to] == -1) {
          mi[to] = cnt + mi[v];
          mi[to] = min(mi[to], mod);
          q.push(make_pair(-mi[to], to));
        } else if (mi[to] > cnt + mi[v]) {
          mi[to] = cnt + mi[v];
          q.push(make_pair(-mi[to], to));
        }
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (mi[i] != -1 && used[i] == 0) {
      dfs(i);
    }
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", mi[i], ma[i]);
  }
  return 0;
}
