#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},
                        {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <class T>
inline T max1(T a, T b, T c = -1234567, T d = -1234567) {
  T ans = a > b ? a : b;
  if (c != -1234567) ans = max1(ans, c);
  if (d != -1234567) ans = max1(ans, d);
  return ans;
}
template <class T>
inline T min1(T a, T b, T c = -1234567, T d = -1234567) {
  T ans = a < b ? a : b;
  if (c != -1234567) ans = min(ans, c);
  if (d != -1234567) ans = min(ans, d);
  return ans;
}
template <class T>
inline T gcd1(T a, T b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd1(b, a % b);
}
template <class T>
inline T lb(T num) {
  return num & (-num);
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / abs1(a) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1) be--;
    if (!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1) be--;
    if (f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}
inline int bitnum(unsigned long long nValue) {
  nValue = ((0xaaaaaaaaaaaaaaaaull & nValue) >> 1) +
           (0x5555555555555555ull & nValue);
  nValue = ((0xccccccccccccccccull & nValue) >> 2) +
           (0x3333333333333333ull & nValue);
  nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue) >> 4) +
           (0x0f0f0f0f0f0f0f0full & nValue);
  nValue = ((0xff00ff00ff00ff00ull & nValue) >> 8) +
           (0x00ff00ff00ff00ffull & nValue);
  nValue = ((0xffff0000ffff0000ull & nValue) >> 16) +
           (0x0000ffff0000ffffull & nValue);
  nValue = ((0xffffffff00000000ull & nValue) >> 32) +
           (0x00000000ffffffffull & nValue);
  return nValue;
}
long long pow(long long n, long long m, long long mod = 0) {
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
const int maxn = 200110;
struct node {
  vector<int> to;
  int val;
  bool operator<(const node &a) const { return to.size() < a.to.size(); }
};
vector<node> orig[maxn];
const long long inf = 1000000000000000000ll;
long long dp[maxn][2];
bool f[maxn], in[maxn];
int m, n;
void dfs(int no, int fa) {
  if (f[no] == 1) return;
  f[no] = 1;
  in[no] = 1;
  dp[no][0] = inf;
  dp[no][1] = 0;
  bool ff = 0;
  for (int i = 0; i < (int)orig[no].size(); i++) {
    long long ans = orig[no][i].val;
    pair<long long, long long> rant = make_pair(ans, ans);
    bool fff = 0, cir = 0;
    for (int j = 0; j < (int)orig[no][i].to.size(); j++) {
      int nxt = orig[no][i].to[j];
      if (!in[nxt])
        dfs(nxt, no);
      else
        fff = 1;
      if (dp[nxt][0] == inf && dp[nxt][1] == 0) cir = 1;
      if (dp[nxt][0] < 0 || (dp[nxt][0] == inf && dp[nxt][1] == 0)) {
        rant = make_pair(-inf, -inf);
        break;
      } else {
        rant.first += dp[nxt][0];
        if (dp[nxt][1] == -1)
          rant.second = -1;
        else if (rant.second > 0 && dp[nxt][1] != -inf)
          rant.second += dp[nxt][1];
      }
    }
    if (cir == 1 && fff == 1) ff = 1;
    if (rant.first < 0) continue;
    if (fff) ff = 1;
    dp[no][0] = min1(dp[no][0], rant.first);
    if (rant.second == -1)
      dp[no][1] = -1;
    else if (dp[no][1] >= 0 && rant.second != -inf)
      dp[no][1] = max(dp[no][1], rant.second);
  }
  if (dp[no][0] == inf) dp[no][0] = -inf;
  if (dp[no][1] == 0) dp[no][1] = -inf;
  if (ff)
    if (dp[no][0] != -inf) dp[no][1] = -1;
  in[no] = 0;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; i++) {
    int id, l;
    scanf("%d%d", &id, &l);
    node ranno;
    ranno.val = 0;
    for (int j = 0; j < l; j++) {
      int num;
      scanf("%d", &num);
      num--;
      if (num == -2)
        ranno.val++;
      else
        ranno.to.push_back(num);
    }
    id--;
    orig[id].push_back(ranno);
  }
  for (int i = 0; i < n; i++) {
    sort(orig[i].begin(), orig[i].end());
  }
  for (int i = 0; i < n; i++)
    if (!f[i]) dfs(i, -1);
  for (int i = 0; i < n; i++) {
    if (dp[i][0] < 0 && dp[i][1] < 0) {
      cout << -1 << ' ' << -1 << endl;
    } else if (dp[i][1] < 0)
      cout << min1(314000000ll, dp[i][0]) << ' ' << -2 << endl;
    else
      cout << min1(314000000ll, dp[i][0]) << ' ' << min1(314000000ll, dp[i][1])
           << endl;
  }
  return 0;
}
