#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int num = 0;
  char c = getchar();
  if (c == '-') return -read();
  while (c >= '0' && c <= '9') {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num;
}
inline long long READ() {
  long long num = 0;
  char c = getchar();
  if (c == '-') return -READ();
  while (c >= '0' && c <= '9') {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num;
}
long long dp[100007], dp2[100007];
long long MAXV = 314000000;
int lgl[100007];
vector<vector<int> > fl[100007];
bool hwam[100007];
void uwm(long long& a) {
  if (a > MAXV) a = MAXV;
}
long long dfsmin(int now) {
  if (lgl[now] == 1) hwam[now] = 1;
  if (lgl[now] == 2) return -1;
  if (dp[now] != ((int)0x3f3f3f3f)) return dp[now];
  lgl[now]++;
  for (int i = 0; i < ((int)(fl[now]).size()); i++) {
    long long ans = 0;
    bool hwww = hwam[now];
    for (int j = 0; j < ((int)(fl[now][i]).size()); j++) {
      long long nowans;
      if (fl[now][i][j] == -1)
        nowans = 1;
      else
        nowans = dfsmin(fl[now][i][j]);
      if (nowans == -1) {
        ans = -1;
        break;
      }
      ans += nowans;
      uwm(ans);
    }
    if (ans != -1) {
      uwm(ans);
      if (dp[now] == -1)
        dp[now] = ans;
      else
        dp[now] = min(dp[now], ans);
    } else
      hwam[now] = hwww;
  }
  lgl[now]--;
  if (dp[now] == ((int)0x3f3f3f3f))
    return dp[now] = -1;
  else
    return dp[now];
}
long long dfsmax(int now) {
  if (lgl[now] == 2) return -1;
  if (dp2[now] != -((int)0x3f3f3f3f)) return dp2[now];
  lgl[now]++;
  for (int i = 0; i < ((int)(fl[now]).size()); i++) {
    long long ans = 0;
    for (int j = 0; j < ((int)(fl[now][i]).size()); j++) {
      long long nowans;
      if (fl[now][i][j] == -1)
        nowans = 1;
      else
        nowans = dfsmax(fl[now][i][j]);
      if (nowans == -2)
        ans = -2;
      else if (nowans == -1) {
        ans = -1;
        break;
      }
      if (ans != -2) ans += nowans;
      uwm(ans);
    }
    if (ans != -1 && ans != -2) {
      uwm(ans);
      if (dp2[now] != -2) dp2[now] = max(dp2[now], ans);
    } else if (ans == -2)
      dp2[now] = -2;
  }
  lgl[now]--;
  if (hwam[now]) {
    if (dp[now] != -1)
      return dp2[now] = -2;
    else
      return dp2[now] = -1;
  }
  if (dp2[now] == -((int)0x3f3f3f3f)) return dp2[now] = -1;
  return dp2[now];
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    fl[a].push_back(vector<int>(b));
    for (int j = 0; j < b; j++)
      scanf("%d", &fl[a][((int)(fl[a]).size()) - 1][j]);
  }
  memset((void*)lgl, 0, sizeof(lgl));
  memset((void*)hwam, 0, sizeof(hwam));
  for (int i = 0; i < 100007; i++) dp[i] = ((int)0x3f3f3f3f);
  for (int i = 1; i <= m; i++)
    if (dp[i] == ((int)0x3f3f3f3f)) dfsmin(i);
  memset((void*)lgl, 0, sizeof(lgl));
  for (int i = 0; i < 100007; i++) dp2[i] = -((int)0x3f3f3f3f);
  for (int i = 1; i <= m; i++)
    if (dp2[i] == -((int)0x3f3f3f3f)) dfsmax(i);
  for (int i = 1; i <= m; i++) printf("%I64d %I64d\n", dp[i], dp2[i]);
  return 0;
}
