#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010, RG = 314000000, INF = ~0U >> 2;
struct edge {
  int a, b, w, pre, next;
} E[MAXN << 2], E0[MAXN << 2];
int n1, n, m, dg[MAXN], res1[MAXN], res2[MAXN], Q[MAXN + 1];
bool vst0[MAXN], vst[MAXN];
void init_d() {
  for (int i = 0; i < n; i++) E[i].pre = E[i].next = E0[i].pre = E0[i].next = i;
  m = n;
}
void add_edge(int a, int b, int w) {
  E[m].a = a;
  E[m].b = b;
  E[m].w = w;
  E[m].pre = E[a].pre;
  E[m].next = a;
  E[a].pre = m;
  E[E[m].pre].next = m;
  E0[m].a = b;
  E0[m].b = a;
  E0[m].w = w;
  E0[m].pre = E0[b].pre;
  E0[m].next = b;
  E0[b].pre = m;
  E0[E0[m].pre].next = m++;
}
void init() {
  int n2, x, y, _, w0;
  scanf("%d%d", &n1, &n2);
  n = n1 + n2 + 1;
  init_d();
  for (int i = 1; i <= n1; i++) {
    scanf("%d%d", &x, &y);
    w0 = 0;
    for (int j = 0; j < y; j++) {
      scanf("%d", &_);
      if (_ == -1)
        w0++;
      else
        add_edge(n1 + _, i, 0);
    }
    add_edge(i, n1 + x, w0);
    if (w0 == y) add_edge(0, i, 0);
  }
}
void solve() {
  int x, y, _;
  for (int i = 0; i < n; i++) res1[i] = INF;
  Q[0] = 0;
  vst[0] = 1;
  for (int front = 0, rear = 0; !(!front && rear == n || front == rear + 1);
       front == n ? front = 0 : front++) {
    x = Q[front];
    if (x <= n1) {
      _ = 0;
      for (int p = E0[x].next; p != x; p = E0[p].next) {
        y = E0[p].b;
        if (res1[y] < INF) {
          _ += res1[y];
          if (_ > RG) _ = RG;
        } else {
          _ = INF;
          break;
        }
      }
    } else {
      _ = INF;
      for (int p = E0[x].next; p != x; p = E0[p].next) {
        y = E0[p].b;
        if (res1[y] < INF && res1[y] + E0[p].w < _) _ = res1[y] + E0[p].w;
      }
      if (_ < INF && _ > RG) _ = RG;
    }
    if (_ < res1[x]) {
      res1[x] = _;
      for (int p = E[x].next; p != x; p = E[p].next) {
        y = E[p].b;
        if (!vst[y]) {
          vst[y] = 1;
          Q[rear == n ? rear = 0 : ++rear] = y;
        }
      }
    }
    vst[x] = 0;
  }
  for (int i = 0; i < n; i++)
    if (res1[i] == INF) res1[i] = res2[i] = -1;
  for (int i = n; i < m; i++) {
    x = E[i].a;
    y = E[i].b;
    if (res1[x] != -1 && res1[y] != -1) dg[y]++;
  }
  int sum = -1;
  for (int i = 0; i < n; i++)
    if (res1[i] != -1 && !dg[i]) {
      vst0[i] = 1;
      Q[++sum] = i;
    }
  for (int front = 0, rear = sum; front <= rear; front++) {
    x = Q[front];
    for (int p = E[x].next; p != x; p = E[p].next) {
      y = E[p].b;
      if (res1[y] != -1) {
        dg[y]--;
        if (!dg[y]) {
          vst0[y] = 1;
          Q[++rear] = y;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) vst[i] = 0;
  for (int i = 0; i < n; i++)
    if (res1[i] != -1) {
      if (vst0[i])
        res2[i] = -INF;
      else
        res2[i] = -2;
    }
  Q[0] = 0;
  vst[0] = 1;
  for (int front = 0, rear = 0; !(!front && rear == n || front == rear + 1);
       front == n ? front = 0 : front++) {
    x = Q[front];
    if (x <= n1) {
      _ = 0;
      for (int p = E0[x].next; p != x; p = E0[p].next) {
        y = E0[p].b;
        if (vst0[y] && res2[y] > -INF) {
          _ += res2[y];
          if (_ > RG) _ = RG;
        } else {
          _ = -INF;
          break;
        }
      }
    } else {
      _ = -INF;
      for (int p = E0[x].next; p != x; p = E0[p].next) {
        y = E0[p].b;
        if (vst0[y] && res2[y] > -INF && res2[y] + E0[p].w > _)
          _ = res2[y] + E0[p].w;
      }
      if (_ > RG) _ = RG;
    }
    if (_ > res2[x]) {
      res2[x] = _;
      for (int p = E[x].next; p != x; p = E[p].next) {
        y = E[p].b;
        if (vst0[y] && !vst[y]) {
          vst[y] = 1;
          Q[rear == n ? rear = 0 : ++rear] = y;
        }
      }
    }
    vst[x] = 0;
  }
}
void pri() {
  for (int i = n1 + 1; i < n; i++) printf("%d %d\n", res1[i], res2[i]);
}
int main() {
  init();
  solve();
  pri();
  return 0;
}
