#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long m, n, mons[100010], num[100010], mn[100010], edeg[100010];
long long cost[100010], maxcost[100010];
vector<long long> edges[100010], redges[100010];
vector<long long> okedge[100010];
vector<long long> v[100010], rv[100010];
long long vis[100010], cyc[100010];
priority_queue<pair<long long, long long> > q;
queue<long long> que;
inline void dfs(long long u) {
  vis[u] = 1;
  for (long long i = 0; i < v[u].size(); i++) {
    long long nxt = v[u][i];
    if (!vis[nxt])
      dfs(nxt);
    else if (vis[nxt] == 1 && cyc[u] == 0) {
      cyc[u] = 1;
      que.push(u);
    }
  }
  vis[u] = 2;
}
inline long long dp(long long u) {
  if (maxcost[u] != -1) return maxcost[u];
  maxcost[u] = 0;
  for (long long i = 0; i < okedge[u].size(); i++) {
    long long s = okedge[u][i];
    long long cur = num[s];
    for (long long j = 0; j < edges[s].size(); j++) {
      cur = min((long long)314000000, cur + dp(edges[s][j]));
    }
    maxcost[u] = max(maxcost[u], cur);
  }
  return maxcost[u];
}
inline bool echeck(long long id) {
  if (mn[mons[id]] == (long long)1000000000007) return false;
  for (long long i = 0; i < edges[id].size(); i++) {
    if (mn[edges[id][i]] == (long long)1000000000007) return false;
  }
  return true;
}
signed main() {
  ios::sync_with_stdio(false);
  cin >> m >> n;
  for (long long i = 1; i <= n; i++) mn[i] = (long long)1000000000007;
  for (long long i = 1; i <= n; i++) maxcost[i] = -1;
  for (long long i = 1; i <= m; i++) {
    cin >> mons[i];
    long long k;
    cin >> k;
    for (long long j = 1; j <= k; j++) {
      long long x;
      cin >> x;
      if (x == -1)
        num[i] += 1;
      else {
        edges[i].push_back(x);
        redges[x].push_back(i);
        edeg[i]++;
      }
    }
    cost[i] = num[i];
    if (edges[i].empty() && mn[mons[i]] > cost[i]) {
      mn[mons[i]] = cost[i];
      q.push(make_pair(-cost[i], mons[i]));
    }
  }
  while (!q.empty()) {
    pair<long long, long long> t = q.top();
    q.pop();
    if (mn[t.second] != -t.first) continue;
    for (long long i = 0; i < redges[t.second].size(); i++) {
      long long s = redges[t.second][i];
      cost[s] = min((long long)314000000, cost[s] - t.first);
      edeg[s]--;
      if (edeg[s] == 0 && mn[mons[s]] > cost[s]) {
        mn[mons[s]] = cost[s];
        q.push(make_pair(-mn[mons[s]], mons[s]));
      }
    }
  }
  for (long long i = 1; i <= m; i++)
    if (echeck(i)) {
      okedge[mons[i]].push_back(i);
      for (long long j = 0; j < edges[i].size(); j++) {
        v[mons[i]].push_back(edges[i][j]);
        rv[edges[i][j]].push_back(mons[i]);
      }
    }
  for (long long i = 1; i <= n; i++)
    if (mn[i] != (long long)1000000000007 && !vis[i]) {
      dfs(i);
    }
  while (!que.empty()) {
    long long t = que.front();
    que.pop();
    for (long long i = 0; i < rv[t].size(); i++) {
      long long u = rv[t][i];
      if (cyc[u] == 0) {
        cyc[u] = 1;
        que.push(u);
      }
    }
  }
  for (long long i = 1; i <= n; i++)
    if (cyc[i] == 0 && mn[i] != (long long)1000000000007) {
      dp(i);
    }
  for (long long i = 1; i <= n; i++) {
    if (mn[i] == (long long)1000000000007)
      cout << "-1 -1" << endl;
    else {
      cout << mn[i] << " ";
      if (cyc[i])
        cout << "-2" << endl;
      else
        cout << maxcost[i] << endl;
    }
  }
  return 0;
}
