#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
void qread(int &x) {
  int neg = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
  x *= neg;
}
const int maxn = 100005;
const long long lim = 314000000;
int n, m;
int a[maxn], b[maxn];
long long s[maxn], os[maxn];
bool in[maxn];
vector<int> gen[maxn], from[maxn], rule[maxn];
long long mn[maxn], mx[maxn];
priority_queue<pair<long long, int> > q;
void dfs(int x) {
  if (mx[x] != -1e18) return;
  if (in[x]) {
    mx[x] = -2;
    return;
  }
  in[x] = true;
  for (int(i) = 0; (i) < rule[x].size(); i++) {
    int id = rule[x][i];
    bool ok = true;
    for (int(j) = 0; (j) < gen[id].size(); j++)
      if (mn[gen[id][j]] < 0) ok = false;
    if (!ok) continue;
    for (int(j) = 0; (j) < gen[id].size(); j++) {
      if (gen[id][j] == x) {
        mx[x] = -2;
        in[x] = false;
        return;
      }
      dfs(gen[id][j]);
      if (mx[gen[id][j]] == -2) {
        mx[x] = -2;
        in[x] = false;
        return;
      }
      s[id] += mx[gen[id][j]];
      s[id] = min(s[id], lim);
    }
    mx[x] = max(mx[x], s[id]);
  }
  in[x] = false;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int(i) = 1; (i) <= n; i++) mn[i] = 1e18, mx[i] = -1e18;
  for (int(i) = 1; (i) <= m; i++) {
    scanf("%d", &a[i]);
    rule[a[i]].push_back(i);
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      if (x < 0)
        s[i]++;
      else
        gen[i].push_back(x), from[x].push_back(i), b[i]++;
    }
    if (!b[i]) {
      if (s[i] < mn[a[i]]) {
        mn[a[i]] = s[i];
        q.push(make_pair(-mn[a[i]], a[i]));
      }
    }
    os[i] = s[i];
  }
  while (!q.empty()) {
    pair<long long, int> x = q.top();
    q.pop();
    x.first = -x.first;
    if (mn[x.second] != x.first) continue;
    for (int(i) = 0; (i) < from[x.second].size(); i++) {
      int y = from[x.second][i];
      b[y]--;
      s[y] += x.first;
      s[y] = min(s[y], lim);
      if (!b[y]) {
        if (s[y] < mn[a[y]]) {
          mn[a[y]] = s[y];
          q.push(make_pair(-mn[a[y]], a[y]));
        }
      }
    }
  }
  for (int(i) = 1; (i) <= n; i++)
    if (mn[i] == 1e18) mn[i] = mx[i] = -1;
  for (int(i) = 1; (i) <= m; i++) s[i] = os[i];
  for (int(i) = 1; (i) <= n; i++)
    if (mx[i] == -1e18) dfs(i);
  for (int(i) = 1; (i) <= n; i++) printf("%lld %lld\n", mn[i], mx[i]);
  return 0;
}
