#include <bits/stdc++.h>
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int inf = 314000000;
const int N = 1e5 + 5;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
bool flag[N];
int vis[N], ansl[N], ansr[N], tol[N], tor[N], n, m;
vector<pair<int, vector<int> > > G[N];
vector<pair<int, int> > oG[N];
vector<int> vv, L[N], out[N];
bool go1(int x) {
  if (vis[x] == 1) return false;
  if (vis[x] == 2) return flag[x];
  vis[x] = 1;
  for (int(i) = 0; (i) < (G[x].size()); (i)++) {
    bool ok = true;
    for (int(jj) = 0; (jj) < (G[x][i].second.size()); (jj)++) {
      int j = G[x][i].second[jj];
      if (!go1(j)) ok = false;
    }
    if (ok) {
      flag[x] = true;
      vis[x] = 2;
      return true;
    }
  }
  vis[x] = 2;
  return false;
}
bool go2(int x) {
  if (vis[x] == 1 || (vis[x] == 2 && flag[x])) return true;
  if (vis[x] == 2 && !flag[x]) return false;
  vis[x] = 1;
  for (int(i) = 0; (i) < (G[x].size()); (i)++) {
    bool ok = true;
    for (int(jj) = 0; (jj) < (G[x][i].second.size()); (jj)++) {
      int j = G[x][i].second[jj];
      if (ansl[j] == -1) {
        ok = false;
        break;
      }
    }
    if (ok) {
      for (int(jj) = 0; (jj) < (G[x][i].second.size()); (jj)++) {
        int j = G[x][i].second[jj];
        if (go2(j)) {
          flag[x] = true;
          vis[x] = 2;
          return true;
        }
      }
    }
  }
  vis[x] = 2;
  return false;
}
void go3() {
  for (int(i) = 0; (i) < (n); (i)++)
    if (ansl[i] >= 0) {
      if (tol[i] < inf) {
        ansl[i] = tol[i];
        pq.push(make_pair(ansl[i], i));
      } else
        ansl[i] = inf;
    }
  while (!pq.empty()) {
    pair<int, int> u = pq.top();
    pq.pop();
    if (u.first > ansl[u.second]) continue;
    for (int(ii) = 0; (ii) < (oG[u.second].size()); (ii)++) {
      pair<int, int> i = oG[u.second][ii];
      out[i.first][i.second]--;
      L[i.first][i.second] += u.first;
      if (L[i.first][i.second] > inf) L[i.first][i.second] = inf;
      if (!out[i.first][i.second] && ansl[i.first] > L[i.first][i.second] &&
          ansl[i.first] >= 0) {
        ansl[i.first] = L[i.first][i.second];
        pq.push(make_pair(ansl[i.first], i.first));
      }
    }
  }
}
int go4(int x) {
  if (vis[x]) return ansr[x];
  vis[x] = 1;
  int ans = 0;
  if (tor[x] != 0) ans = tor[x];
  for (int(i) = 0; (i) < (G[x].size()); (i)++) {
    int len = G[x][i].first;
    bool ok = true;
    for (int(jj) = 0; (jj) < (G[x][i].second.size()); (jj)++) {
      int j = G[x][i].second[jj];
      if (ansr[j] < 0) {
        ok = false;
        break;
      }
      len += go4(j);
      if (len > inf) len = inf;
    }
    if (ok) ans = max(ans, len);
  }
  if (ans > inf) ans = inf;
  return ansr[x] = ans;
}
int main() {
  m = getint();
  n = getint();
  for (int(i) = 0; (i) < (n); (i)++) tol[i] = 1000000000;
  for (int(i) = 0; (i) < (m); (i)++) {
    int x = getint() - 1;
    int op = getint(), ans = 0;
    vv.clear();
    for (int(j) = 0; (j) < (op); (j)++) {
      int y = getint() - 1;
      if (y == -2)
        ans++;
      else {
        vv.push_back(y);
        oG[y].push_back(make_pair(x, G[x].size()));
      }
    }
    if (ans == op) {
      tol[x] = min(tol[x], ans);
      tor[x] = max(tor[x], ans);
      vis[x] = 2;
      flag[x] = true;
    } else {
      out[x].push_back(vv.size());
      G[x].push_back(make_pair(ans, vv));
      L[x].push_back(ans);
    }
  }
  for (int(i) = 0; (i) < (n); (i)++)
    if (!vis[i]) go1(i);
  for (int(i) = 0; (i) < (n); (i)++)
    if (!flag[i]) {
      ansl[i] = -1;
      ansr[i] = -1;
    }
  memset(vis, 0, sizeof(vis));
  memset(flag, 0, sizeof(flag));
  for (int(i) = 0; (i) < (n); (i)++)
    if (!vis[i] && ansl[i] != -1) go2(i);
  for (int(i) = 0; (i) < (n); (i)++)
    if (flag[i] && ansl[i] != -1) ansr[i] = -2;
  memset(vis, 0, sizeof(vis));
  go3();
  for (int(i) = 0; (i) < (n); (i)++)
    if (!vis[i] && ansr[i] >= 0) go4(i);
  for (int(i) = 0; (i) < (n); (i)++) printf("%d %d\n", ansl[i], ansr[i]);
  return 0;
}
