#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
const int maxn = 100000 + 5;
const int up = 314000000;
int m, n;
int id[maxn], nxt_sz[maxn];
long long d[maxn], dis[maxn], opt[maxn];
bool vis[maxn];
int color[maxn];
vector<int> idx[maxn];
vector<int> nxt[maxn];
vector<int> pre[maxn];
void dijkstra() {
  long long tmp[maxn];
  priority_queue<pair<long long, int> > q;
  fill(dis + 1, dis + 1 + n, inf);
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < m; ++i) {
    tmp[i] = d[i];
    if (nxt_sz[i] == 0) dis[id[i]] = min(dis[id[i]], d[i]);
  }
  for (int i = 1; i <= n; ++i)
    if (dis[i] != inf) q.push(pair<long long, int>(-dis[i], i));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < pre[u].size(); ++i) {
      int v = pre[u][i];
      tmp[v] += dis[u];
      --nxt_sz[v];
      if (nxt_sz[v] == 0 && tmp[v] < dis[id[v]]) {
        dis[id[v]] = tmp[v];
        q.push(pair<long long, int>(-dis[id[v]], id[v]));
      }
    }
  }
}
void dfs(int u) {
  if (dis[u] == inf) {
    opt[u] = inf;
    color[u] = 2;
    return;
  }
  color[u] = 1;
  opt[u] = dis[u];
  for (int k = 0; k < idx[u].size(); ++k) {
    int i = idx[u][k];
    long long cnt = d[i];
    for (int j = 0; j < nxt[i].size(); ++j) {
      int v = nxt[i][j];
      if (!color[v]) dfs(v);
      if (color[v] == 1 || opt[v] == -2) {
        cnt = -2;
      }
      if (opt[v] == inf) {
        cnt = -1;
        break;
      }
      if (cnt != -2) cnt += opt[v];
    }
    if (cnt == -2) {
      opt[u] = -2;
      break;
    } else {
      opt[u] = max(opt[u], cnt);
    }
  }
  color[u] = 2;
}
int f(long long x) {
  if (x == inf) return -1;
  if (x > up) return up;
  return x;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; ++i) {
    int l;
    scanf("%d%d", &id[i], &l);
    idx[id[i]].push_back(i);
    while (l--) {
      int x;
      scanf("%d", &x);
      if (x < 0) {
        ++d[i];
      } else {
        nxt[i].push_back(x);
        ++nxt_sz[i];
        pre[x].push_back(i);
      }
    }
  }
  dijkstra();
  for (int i = 1; i <= n; ++i)
    if (!color[i]) dfs(i);
  for (int i = 1; i <= n; ++i) printf("%d %d\n", f(dis[i]), f(opt[i]));
  return 0;
}
