#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll m, n;
ll mn[960000 + 5], mx[960000 + 5];
bool vis[960000 + 5], inq[960000 + 5];
vector<ll> u[960000 + 5], v[960000 + 5];
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > q;
ll minn(ll a, ll b) { return a < b ? a : b; }
ll maxn(ll a, ll b) { return a > b ? a : b; }
struct Data {
  ll id, w, r, sum;
  vector<ll> v;
} p[960000 + 5];
void dij() {
  memset(mn, 0x7f, sizeof mn);
  ll t;
  ll d, x;
  while (!q.empty()) {
    d = minn(0x3f3f3f3f, q.top().first);
    x = q.top().second;
    q.pop();
    if (d < mn[x]) {
      for (ll i = 0; i < (ll)v[x].size(); i++) {
        t = v[x][i];
        if (mn[x] > 0x3f3f3f3f) {
          p[t].r--;
          p[t].sum += d;
        } else {
          p[t].sum += d - mn[x];
        }
        if (!p[t].r) {
          q.push(make_pair(p[t].sum, p[t].id));
        }
        p[t].sum = minn(p[t].sum, 0x3f3f3f3f);
      }
      mn[x] = d;
    }
  }
  for (ll i = 1; i <= n; i++) {
    if (mn[i] > 0x3f3f3f3f) {
      mn[i] = mx[i] = -1;
    }
  }
}
void dfs(ll x) {
  if (vis[x] || inq[x]) {
    return;
  }
  vis[x] = inq[x] = 1;
  ll v, t, sum;
  for (ll i = 0; i < (ll)u[x].size(); i++) {
    t = u[x][i];
    sum = p[t].w;
    for (ll j = 0; j < (ll)p[t].v.size(); j++) {
      if (mx[p[t].v[j]] == -1) {
        sum = -1;
        break;
      }
    }
    if (sum == -1) {
      continue;
    }
    for (ll j = 0; j < (ll)p[t].v.size(); j++) {
      v = p[t].v[j];
      dfs(v);
      if (inq[v] || mx[v] == 0x3f3f3f3f) {
        sum = 0x3f3f3f3f;
        break;
      }
      sum += mx[v];
    }
    mx[x] = maxn(mx[x], sum);
  }
  inq[x] = 0;
}
int main() {
  cin >> m >> n;
  ll x, y;
  for (ll i = 1; i <= m; i++) {
    cin >> p[i].id;
    u[p[i].id].push_back(i);
    cin >> x;
    for (ll j = 1; j <= x; j++) {
      cin >> y;
      if (y == -1) {
        p[i].w++;
      } else {
        p[i].r++;
        p[i].v.push_back(y);
        v[y].push_back(i);
      }
    }
    if (p[i].w == x) {
      q.push(make_pair(p[i].w, p[i].id));
    }
    p[i].sum = p[i].w;
  }
  dij();
  for (ll i = 1; i <= n; i++) {
    if (mx[i] != -1 && !vis[i]) {
      dfs(i);
    }
  }
  for (ll i = 1; i <= n; i++) {
    if (mx[i] == 0x3f3f3f3f) {
      mx[i] = -2;
    }
  }
  for (ll i = 1; i <= n; i++) {
    cout << minn(mn[i], 314000000) << " " << minn(mx[i], 314000000) << endl;
  }
  return 0;
}
