#include <bits/stdc++.h>
using namespace std;
const int N = 100005, INF = 314000000;
int m, n, odl[N];
int st[N], dia[N], pot[N];
int odl2[N], dia2[N], pot2[N], pocz[N];
vector<int> e[N], d[N];
priority_queue<pair<int, int>> pq;
queue<int> q;
bool cz[N];
void add(int kt) {
  if (odl[st[kt]] == -1 || odl[st[kt]] > dia[kt]) {
    odl[st[kt]] = dia[kt];
    pq.push(make_pair(-dia[kt], st[kt]));
  }
}
void add2(int kt) {
  if (odl2[st[kt]] < dia2[kt]) odl2[st[kt]] = dia2[kt];
  pocz[st[kt]]--;
  if (pocz[st[kt]] == 0) q.push(st[kt]);
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < n; i++) odl[i] = odl2[i] = -1;
  for (int i = 0; i < m; i++) {
    scanf("%d", &st[i]);
    st[i]--;
    pocz[st[i]]++;
    int s;
    scanf("%d", &s);
    while (s--) {
      int x;
      scanf("%d", &x);
      x--;
      if (x == -2) {
        dia[i]++;
        dia2[i]++;
      } else {
        pot[i]++;
        pot2[i]++;
        e[x].push_back(i);
        d[st[i]].push_back(x);
      }
    }
    if (!pot[i]) add(i);
  }
  while (!pq.empty()) {
    pair<int, int> k = pq.top();
    pq.pop();
    int u = k.second;
    if (-k.first != odl[u]) continue;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i];
      pot[v]--;
      dia[v] += odl[u];
      if (dia[v] > INF) dia[v] = INF;
      if (!pot[v]) add(v);
    }
  }
  for (int i = 0; i < n; i++) {
    if (odl[i] == -1) {
      for (int j = 0; j < e[i].size(); j++) {
        int v = e[i][j];
        if (!cz[v]) {
          cz[v] = 1;
          pot2[v] = -1;
          pocz[st[v]]--;
        }
      }
    }
  }
  for (int i = 0; i < m; i++)
    if (!pot2[i]) add2(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i];
      pot2[v]--;
      dia2[v] += odl2[u];
      if (dia2[v] > INF) dia2[v] = INF;
      if (!pot2[v]) add2(v);
    }
  }
  for (int i = 0; i < n; i++) {
    if (odl[i] == -1)
      puts("-1 -1");
    else
      printf("%d %d\n", odl[i], (!pocz[i] ? odl2[i] : -2));
  }
  return 0;
}
