#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q;
vector<int> edge[110000], b[110000], E[110000];
int Max[110000], f[110000], n, m, vis[110000], a[110000], cnt[110000],
    dis[110000], s[110000];
bool ok[110000];
int dfs(int u) {
  if (vis[u]) return Max[u];
  vis[u] = 1;
  for (int i = 0; i < E[u].size(); i++) {
    int t = E[u][i], pd = 1;
    for (int j = 0; j < b[t].size(); j++)
      if (f[b[t][j]] > 1000000000) {
        pd = 0;
        break;
      }
    if (!pd) continue;
    int ff = s[t];
    for (int j = 0; j < b[t].size(); j++)
      if (vis[b[t][j]] == 1)
        ok[u] = 1;
      else {
        ff = min(ff + dfs(b[t][j]), 314000000);
        if (ok[b[t][j]]) ok[u] = 1;
      }
    Max[u] = max(Max[u], ff);
  }
  vis[u] = 2;
  return Max[u];
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    int k;
    scanf("%d", &k);
    E[a[i]].push_back(i);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      if (x > 0)
        b[i].push_back(x), edge[x].push_back(i), ++cnt[i];
      else
        dis[i]++, s[i]++;
    }
    if (!cnt[i]) Q.push(make_pair(dis[i], a[i]));
  }
  memset(f, 60, sizeof f);
  while (!Q.empty()) {
    pair<int, int> rec = Q.top();
    Q.pop();
    int x = rec.first, y = rec.second;
    if (vis[y]) continue;
    vis[y] = 1;
    f[y] = x;
    for (int i = 0; i < edge[y].size(); ++i) {
      int t = edge[y][i];
      cnt[t]--;
      dis[t] = min(dis[t] + x, 314000000);
      if (!cnt[t]) Q.push(make_pair(dis[t], a[t]));
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; i++)
    if (i < 1000000000) dfs(i);
  for (int i = 1; i <= n; i++)
    if (f[i] > 1000000000)
      printf("-1 -1\n");
    else
      printf("%d %d\n", f[i], ok[i] ? -2 : Max[i]);
  return 0;
}
