#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 4e5 + 7;
const int inf = 314000000;
vector<int> rule[N];
int cost[N], from[N], cnt[N];
vector<int> G[N], rG[N];
int mn[N], mx[N];
bool vis[N], used[N], inuse[N];
int n, m;
void getdp(int u) {
  if (!u || used[u] || inuse[u]) return;
  inuse[u] = true;
  mx[u] = -1;
  for (int r : G[u]) {
    int sum = cost[r];
    bool flag = true;
    for (int i = 0; i < rule[r].size(); i++)
      if (!vis[rule[r][i]]) {
        flag = false;
        break;
      }
    if (!flag) continue;
    for (int i = 0; i < rule[r].size(); i++) {
      int v = rule[r][i];
      getdp(v);
      if (inuse[v] || mx[v] == -2) {
        mx[u] = -2;
        return;
      }
      sum += mx[v];
      if (sum > inf) sum = inf;
    }
    mx[u] = max(mx[u], sum);
  }
  inuse[u] = false;
  used[u] = true;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) {
    int num;
    scanf("%d%d", &from[i], &num);
    G[from[i]].push_back(i);
    while (num--) {
      int x;
      scanf("%d", &x);
      if (x == -1) {
        ++cost[i];
      } else {
        rule[i].push_back(x);
        rG[x].push_back(i);
      }
    }
    if (rule[i].empty()) {
      rule[i].push_back(0);
      rG[0].push_back(i);
    }
    cnt[i] = rule[i].size();
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  mn[0] = 0;
  q.push(make_pair(0, 0));
  vis[0] = true;
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int d = p.first, u = p.second;
    if (mn[u] < d) continue;
    for (int r : rG[u]) {
      --cnt[r];
      if (cnt[r]) continue;
      int sum = cost[r];
      for (int i = 0; i < rule[r].size(); i++) {
        sum += mn[rule[r][i]];
        if (sum > inf) sum = inf;
      }
      if (!vis[from[r]] || sum < mn[from[r]]) {
        mn[from[r]] = sum;
        vis[from[r]] = true;
        q.push(make_pair(mn[from[r]], from[r]));
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      mn[i] = mx[i] = -1;
    } else {
      getdp(i);
    }
  for (int i = 1; i <= n; i++) printf("%d %d\n", mn[i], mx[i]);
  return 0;
}
