#include <bits/stdc++.h>
using namespace std;
vector<int> splits[100005], inrule[100005];
vector<int> L[100005];
int monster[100005], diamonds[100005], cont[100005];
int best[100005], best2[100005];
bool visited[100005], in_stack[100005];
void dfs(int cur) {
  if (visited[cur]) return;
  visited[cur] = true;
  in_stack[cur] = true;
  best2[cur] = 0;
  for (int i = splits[cur].size() - 1, to; i >= 0; --i) {
    to = splits[cur][i];
    bool ok = true;
    for (int j = L[to].size() - 1; j >= 0; --j)
      if (best[L[to][j]] == -1) ok = false;
    if (!ok) continue;
    int aux = diamonds[to];
    for (int j = L[to].size() - 1; j >= 0 && aux != -2; --j) {
      if (in_stack[L[to][j]])
        aux = -2;
      else {
        dfs(L[to][j]);
        if (best2[L[to][j]] == -2)
          aux = -2;
        else
          aux = min(314000000, aux + best2[L[to][j]]);
      }
    }
    if (aux == -2) {
      best2[cur] = -2;
      break;
    } else
      best2[cur] = max(best2[cur], aux);
  }
  in_stack[cur] = false;
}
int main() {
  int m, n;
  scanf("%d %d", &m, &n);
  for (int i = 0, s, k; i < m; ++i) {
    scanf("%d %d", &s, &k);
    splits[s].push_back(i);
    diamonds[i] = 0;
    monster[i] = s;
    for (int j = 0, x; j < k; ++j) {
      scanf("%d", &x);
      if (x == -1)
        ++diamonds[i];
      else {
        L[i].push_back(x);
        inrule[x].push_back(i);
        ++cont[i];
      }
    }
  }
  priority_queue<pair<int, int> > Q;
  pair<int, int> aux;
  memset(best, -1, sizeof best);
  for (int i = 0; i < m; ++i) {
    if (cont[i] == 0) {
      if (best[monster[i]] == -1 || diamonds[i] < best[monster[i]]) {
        Q.push(make_pair(-diamonds[i], monster[i]));
        best[monster[i]] = diamonds[i];
      }
    }
  }
  while (!Q.empty()) {
    aux = Q.top();
    Q.pop();
    if (-aux.first != best[aux.second]) continue;
    for (int i = inrule[aux.second].size() - 1, to; i >= 0; --i) {
      to = inrule[aux.second][i];
      --cont[to];
      if (cont[to] == 0) {
        int sum = diamonds[to];
        for (int j = L[to].size() - 1; j >= 0; --j)
          sum = min(314000000, sum + best[L[to][j]]);
        if (best[monster[to]] == -1 || sum < best[monster[to]]) {
          Q.push(make_pair(-sum, monster[to]));
          best[monster[to]] = sum;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (best[i] == -1)
      best2[i] = -1;
    else
      dfs(i);
  }
  for (int i = 1; i <= n; ++i) printf("%d %d\n", best[i], best2[i]);
  return 0;
}
