#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 1e9;
const int INF2 = 314e6;
vector<int> d[maxn];
vector<int> cnt[maxn];
vector<int> sum[maxn];
vector<vector<int> > b[maxn];
vector<pair<int, int> > e[maxn];
set<pair<int, int> > q;
int ansmin[maxn];
bool use[maxn];
int ansmax[maxn];
int cnt2[maxn];
inline int plusssss(int a, int b) { return (a + b > INF2) ? INF2 : a + b; }
int main() {
  int n, m, v, x, count;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &v, &count);
    v--;
    vector<int> temp;
    int diamond = 0;
    for (int j = 0; j < count; j++) {
      scanf("%d", &x);
      if (x == -1) {
        diamond++;
        continue;
      }
      temp.push_back(x - 1);
    }
    d[v].push_back(diamond);
    b[v].push_back(temp);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)b[i].size(); j++)
      for (int k = 0; k < (int)b[i][j].size(); k++)
        e[b[i][j][k]].push_back(make_pair(i, j));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)b[i].size(); j++) {
      cnt[i].push_back(b[i][j].size());
      sum[i].push_back(d[i][j]);
    }
  for (int i = 0; i < n; i++) ansmin[i] = inf;
  for (int i = 0; i < n; i++) {
    int cost = inf;
    for (int j = 0; j < (int)b[i].size(); j++)
      if (b[i][j].size() == 0 && d[i][j] < cost) cost = d[i][j];
    if (cost != inf) {
      q.insert(make_pair(cost, i));
      ansmin[i] = cost;
      use[i] = 1;
    }
  }
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    for (int i = 0; i < (int)e[v].size(); i++) {
      pair<int, int> pr = e[v][i];
      cnt[pr.first][pr.second]--;
      sum[pr.first][pr.second] = plusssss(sum[pr.first][pr.second], ansmin[v]);
      if (cnt[pr.first][pr.second] == 0 &&
          sum[pr.first][pr.second] < ansmin[pr.first]) {
        q.erase(make_pair(ansmin[pr.first], pr.first));
        ansmin[pr.first] = sum[pr.first][pr.second];
        q.insert(make_pair(ansmin[pr.first], pr.first));
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (ansmin[i] == inf) ansmin[i] = -1;
  for (int i = 0; i < n; i++) e[i].clear();
  for (int i = 0; i < n; i++) {
    cnt2[i] = 0;
    for (int j = 0; j < (int)b[i].size(); j++) {
      bool flag = 1;
      for (int k = 0; k < (int)b[i][j].size(); k++)
        if (ansmin[b[i][j][k]] == -1) flag = 0;
      if (!flag) {
        cnt[i][j] = 0;
        sum[i][j] = 0;
        continue;
      }
      cnt2[i]++;
      cnt[i][j] = b[i][j].size();
      sum[i][j] = d[i][j];
      for (int k = 0; k < (int)b[i][j].size(); k++)
        e[b[i][j][k]].push_back(make_pair(i, j));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)b[i].size(); j++)
      if (b[i][j].size() == 0) cnt2[i]--;
    if (cnt2[i] == 0) {
      int cost = 0;
      for (int j = 0; j < (int)b[i].size(); j++) cost = max(cost, sum[i][j]);
      ansmax[i] = cost;
      q.insert(make_pair(cost, i));
    }
  }
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    for (int i = 0; i < (int)e[v].size(); i++) {
      pair<int, int> pr = e[v][i];
      sum[pr.first][pr.second] = plusssss(sum[pr.first][pr.second], ansmax[v]);
      cnt[pr.first][pr.second]--;
      if (cnt[pr.first][pr.second] == 0) cnt2[pr.first]--;
      if (cnt2[pr.first] == 0) {
        int cost = 0;
        for (int j = 0; j < (int)sum[pr.first].size(); j++)
          cost = max(cost, sum[pr.first][j]);
        ansmax[pr.first] = cost;
        q.insert(make_pair(cost, pr.first));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (ansmin[i] == -1) {
      ansmax[i] = -1;
      continue;
    }
    if (ansmax[i] == 0) {
      ansmax[i] = -2;
      continue;
    }
  }
  for (int i = 0; i < n; i++) printf("%d %d\n", ansmin[i], ansmax[i]);
  return 0;
}
