#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct EDGE {
  int dia, cur, from;
  vector<int> mon;
} e[maxn];
vector<int> re[maxn];
int n, m;
int dis[maxn];
int sum[maxn];
int dp[maxn], cnt[maxn];
void dijkstra() {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (int i = 1; i <= n; i++) dis[i] = 314000000 + 1;
  for (int i = 0; i < m; i++)
    if ((int((e[i].mon).size())) == 0) {
      dis[e[i].from] = min(dis[e[i].from], e[i].dia);
    }
  for (int i = 1; i <= n; i++)
    if (dis[i] != 314000000 + 1) q.push(make_pair(dis[i], i));
  while (!q.empty()) {
    int d = q.top().first, u = q.top().second;
    q.pop();
    if (dis[u] != d) continue;
    for (int i = 0; i < (int((re[u]).size())); i++) {
      int id = re[u][i];
      e[id].cur--;
      if (e[id].cur == 0) {
        int tmp = e[id].dia;
        for (int j = 0; j < (int((e[id].mon).size())); j++)
          tmp = min(314000000, dis[e[id].mon[j]] + tmp);
        if (tmp < dis[e[id].from]) {
          dis[e[id].from] = tmp;
          q.push(make_pair(tmp, e[id].from));
        }
      }
    }
  }
  return;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) {
    int c;
    scanf("%d%d", &e[i].from, &c);
    e[i].cur = c;
    for (int j = 0; j < c; j++) {
      int x;
      scanf("%d", &x);
      if (x == -1)
        e[i].dia++, e[i].cur--;
      else {
        e[i].mon.push_back(x);
        re[x].push_back(i);
      }
    }
  }
  dijkstra();
  for (int i = 0; i < m; i++) {
    bool ok = true;
    e[i].cur = e[i].mon.size();
    for (int j = 0; j < e[i].cur; j++)
      ok &= (dis[e[i].mon[j]] != 314000000 + 1);
    if (ok) cnt[e[i].from]++;
  }
  queue<int> q;
  for (int i = 0; i < m; i++) {
    if (e[i].mon.size() == 0) {
      dp[e[i].from] = max(e[i].dia, dp[e[i].from]);
      cnt[e[i].from]--;
      if (!cnt[e[i].from]) q.push(e[i].from);
    }
  }
  memset(sum, 0, sizeof(sum));
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < (int((re[cur]).size())); i++) {
      int u = re[cur][i];
      if (dis[e[u].from] == 314000000 + 1) continue;
      sum[u] += dp[cur];
      sum[u] = min(sum[u], 314000000);
      e[u].cur--;
      if (e[u].cur == 0) {
        cnt[e[u].from]--;
        dp[e[u].from] = max(min(314000000, sum[u] + e[u].dia), dp[e[u].from]);
        if (!cnt[e[u].from]) q.push(e[u].from);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] == 314000000 + 1)
      puts("-1 -1");
    else {
      printf("%d ", dis[i]);
      if (!cnt[i])
        printf("%d\n", dp[i]);
      else
        puts("-2");
    }
  }
  return 0;
}
