#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const int N = 100005;
long long lim = 314000000;
long long len[N];
vector<long long> input[N];
struct split {
  vector<int> p;
  long long val, u, cnt, nval;
} a[100005];
vector<int> in[N];
long long minn[N][2], maxx[N];
int vis[N];
int n, m;
queue<int> q;
void getMinn() {
  for (int i = 1; i <= n; i++) minn[i][0] = minn[i][1] = inf;
  minn[0][0] = 0;
  vis[0] = 1;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 0; i < in[u].size(); i++) {
      int x = in[u][i];
      int v = a[x].u;
      if (minn[u][1] == inf) {
        a[x].cnt--;
        a[x].val += minn[u][0];
      } else
        a[x].val -= (minn[u][1] - minn[u][0]);
      if (a[x].cnt == 0 && a[x].val < minn[v][0]) {
        minn[v][0] = a[x].val;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
    minn[u][1] = minn[u][0];
  }
  for (int i = 1; i <= n; i++) {
    if (minn[i][0] == inf) minn[i][0] = -1;
    if (minn[i][0] > lim) minn[i][0] = lim;
  }
}
void dfs(int u) {
  vis[u] = -1;
  if (minn[u][0] == -1) {
    maxx[u] = -1;
    vis[u] = 1;
    return;
  }
  maxx[u] = -1;
  for (int i = 0; i < in[u].size(); i++) {
    vector<int> p = a[in[u][i]].p;
    long long val = a[in[u][i]].nval;
    for (int j = 0; j < p.size(); j++) {
      int v = p[j];
      if (vis[v] == -1)
        val = -2;
      else {
        if (vis[v] == 0) dfs(v);
        if (maxx[v] == -2)
          val = -2;
        else {
          if (maxx[v] == -1) {
            val = -1;
            break;
          } else if (val != -2)
            val += maxx[v];
        }
      }
    }
    if (val != -1) {
      if (maxx[u] == -1)
        maxx[u] = val;
      else {
        if (val == -2)
          maxx[u] = -2;
        else if (maxx[u] != -2)
          maxx[u] = max(maxx[u], val);
      }
    }
  }
  vis[u] = 1;
}
void getMaxx() {
  for (int i = 1; i <= n; i++) {
    in[i].clear();
    vis[i] = 0;
  }
  for (int i = 0; i < m; i++) in[a[i].u].push_back(i);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    if (maxx[i] > lim) maxx[i] = lim;
  }
}
int main() {
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    cin >> a[i].u >> len[i];
    for (int j = 0; j < len[i]; j++) {
      long long temp;
      cin >> temp;
      input[i].push_back(temp);
      if (temp == -1)
        a[i].val++;
      else {
        a[i].p.push_back(temp);
        in[temp].push_back(i);
      }
    }
    a[i].cnt = a[i].p.size();
    a[i].nval = a[i].val;
    if (a[i].cnt == 0) {
      in[0].push_back(i);
    }
  }
  getMinn();
  getMaxx();
  for (int i = 1; i <= n; i++) {
    cout << minn[i][0] << " " << maxx[i] << "\n";
  }
  return 0;
}
