#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long llread() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct que {
  int x, dia, sum, num;
  vector<int> G;
} a[100010];
struct Node {
  int d, u;
  inline bool operator<(const Node& rhs) const { return d > rhs.d; }
};
priority_queue<Node> Q;
vector<int> Replace[100010], Way[100010];
int mn[100010], mx[100010];
bool vis[100010], inq[100010];
int n, m;
inline void dp(int x) {
  if (vis[x] || inq[x]) return;
  vis[x] = 1;
  inq[x] = 1;
  for (int i = (0); i < (Way[x].size()); i++) {
    int id = Way[x][i], sum = a[id].dia;
    for (int j = (0); j < (a[id].G.size()); j++)
      if (mx[a[id].G[j]] == -1) {
        sum = -1;
        break;
      }
    if (sum == -1) continue;
    for (int j = (0); j < (a[id].G.size()); j++) {
      int v = a[id].G[j];
      dp(v);
      if (mx[v] >= 1047483647 || inq[v]) {
        sum = 1047483647;
        break;
      }
      sum += mx[v];
    }
    mx[x] = max(mx[x], sum);
  }
  inq[x] = 0;
}
inline void solve() {
  memset(mn, 0x3f, sizeof(mn));
  while (!Q.empty()) {
    int d = min(1047483647, Q.top().d);
    int x = Q.top().u;
    Q.pop();
    if (d >= mn[x]) continue;
    for (int i = (0); i < (Replace[x].size()); i++) {
      int v = Replace[x][i];
      if (mn[x] > 1047483647)
        a[v].num--;
      else
        a[v].sum -= mn[x];
      a[v].sum += d;
      if (a[v].num == 0) Q.push((Node){a[v].sum, a[v].x});
      a[v].sum = min(a[v].sum, 1047483647);
    }
    mn[x] = d;
  }
  for (int i = (1); i <= (n); i++)
    if (mn[i] > 1047483647) mx[i] = mn[i] = -1;
  for (int i = (1); i <= (n); i++)
    if (mx[i] != -1 && !vis[i]) dp(i);
}
inline void print() {
  for (int i = (1); i <= (n); i++)
    if (mx[i] == 1047483647) mx[i] = -2;
  for (int i = (1); i <= (n); i++) {
    mx[i] = min(mx[i], 314000000);
    mn[i] = min(mn[i], 314000000);
  }
  for (int i = (1); i <= (n); i++) {
    printf("%d %d\n", mn[i], mx[i]);
  }
}
int main() {
  m = read(), n = read();
  for (int i = (1); i <= (m); i++) {
    a[i].x = read();
    int ft = read();
    Way[a[i].x].push_back(i);
    for (int j = (1); j <= (ft); j++) {
      int x = read();
      if (x == -1)
        a[i].dia++;
      else {
        a[i].num++;
        a[i].G.push_back(x);
        Replace[x].push_back(i);
      }
    }
    if (a[i].num == 0) Q.push((Node){a[i].dia, a[i].x});
    a[i].sum = a[i].dia;
  }
  solve();
  print();
  return 0;
}
