#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10, INF = 314000000;
int n, m, d[MAXN], f[MAXN], p[MAXN], co[MAXN], g[MAXN], used[MAXN];
bool vis[MAXN], l[MAXN];
vector<int> e[MAXN], v[MAXN], c[MAXN];
priority_queue<pair<int, int> > q;
void DFS(int first) {
  if (used[first]) return;
  used[first] = 1;
  for (int i = 0; i < (int)e[first].size(); ++i) {
    int second = e[first][i];
    bool flag = false;
    for (int k = 0; k < (int)v[second].size(); ++k)
      if (v[second][k] > 0 && f[v[second][k]] > (int)1e9) {
        flag = true;
        break;
      }
    if (flag) continue;
    int Tohka = 0;
    for (int k = 0; k < (int)v[second].size(); ++k) {
      int t = v[second][k];
      if (t > 0) {
        if (used[t] == 1)
          flag = true;
        else
          DFS(t), Tohka = min(Tohka + g[t], INF), l[first] |= l[t];
      } else
        ++Tohka, Tohka = min(Tohka, INF);
    }
    g[first] = max(g[first], Tohka);
    l[first] |= flag;
  }
  used[first] = 2;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &p[i]);
    int num;
    scanf("%d", &num);
    e[p[i]].push_back(i);
    for (int j = 1; j <= num; ++j) {
      int first;
      scanf("%d", &first);
      v[i].push_back(first);
      if (first > 0)
        c[first].push_back(i), ++d[i];
      else
        ++co[i];
    }
    if (!d[i]) q.push(make_pair(-co[i], p[i]));
  }
  memset(f, 0x3f, sizeof(f));
  while (!q.empty()) {
    pair<int, int> w = q.top();
    q.pop();
    int first = w.second;
    if (vis[first]) continue;
    vis[first] = true;
    f[first] = -w.first;
    for (int i = 0; i < (int)c[first].size(); ++i) {
      int second = c[first][i];
      co[second] = min(co[second] + f[first], INF);
      --d[second];
      if (!d[second]) q.push(make_pair(-co[second], p[second]));
    }
  }
  for (int i = 1; i <= n; ++i)
    if (f[i] < (int)1e9) DFS(i);
  for (int i = 1; i <= n; ++i)
    if (f[i] < (int)1e9)
      if (l[i])
        printf("%d -2\n", f[i]);
      else
        printf("%d %d\n", f[i], g[i]);
    else
      puts("-1 -1");
  fclose(stdin);
  fclose(stdout);
  return 0;
}
