#include <bits/stdc++.h>
using namespace std;
const int inf = 314000000;
int n, m, id[111111], dis[111111], dp[111111];
int val[111111], sum[111111], deg[111111];
int vis[111111];
vector<int> str[111111];
vector<int> to[111111];
vector<int> fr[111111];
int add(int x, int y) {
  int s = x + y;
  return min(s, inf);
}
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] = 0x3f3f3f3f;
  }
  for (int i = 1; i <= m; i++) {
    if (to[i].empty()) {
      if (val[i] < dis[id[i]]) {
        dis[id[i]] = val[i];
        q.push(make_pair(dis[id[i]], id[i]));
      }
    }
  }
  while (!q.empty()) {
    int x = q.top().second, d = q.top().first;
    q.pop();
    if (dis[x] != d) continue;
    for (int i = 0; i < fr[x].size(); i++) {
      deg[fr[x][i]]--;
      sum[fr[x][i]] = add(sum[fr[x][i]], dis[x]);
      if (!deg[fr[x][i]] && dis[id[fr[x][i]]] > sum[fr[x][i]]) {
        dis[id[fr[x][i]]] = sum[fr[x][i]];
        q.push(make_pair(dis[id[fr[x][i]]], id[fr[x][i]]));
      }
    }
  }
}
int dfs(int x) {
  if (vis[x]) return -2;
  if (dp[x] != -1) return dp[x];
  vis[x] = 1;
  for (int i = 0; i < str[x].size(); i++) {
    int y = str[x][i], sum = 0, t = 0;
    for (int j = 0; j < to[y].size(); t = ++j) {
      if (dis[to[y][j]] == 0x3f3f3f3f) {
        break;
      }
    }
    if (t < to[y].size()) {
      continue;
    }
    for (int j = 0; j < to[y].size(); j++) {
      int t = dfs(to[y][j]);
      if (t == -2) {
        vis[x] = 0;
        return dp[x] = -2;
      }
      sum = add(sum, t);
    }
    sum = add(sum, val[y]);
    dp[x] = max(dp[x], sum);
  }
  vis[x] = 0;
  return dp[x];
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= m; i++) {
    int cnt;
    scanf("%d%d", &id[i], &cnt);
    str[id[i]].push_back(i);
    while (cnt--) {
      int x;
      scanf("%d", &x);
      if (x == -1) {
        val[i]++;
        sum[i]++;
        continue;
      }
      to[i].push_back(x);
      fr[x].push_back(i);
    }
    deg[i] = to[i].size();
  }
  dijkstra();
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    if (dis[i] == 0x3f3f3f3f) {
      puts("-1 -1");
    } else {
      printf("%d %d\n", dis[i], dfs(i));
    }
  }
  return 0;
}
