#include <bits/stdc++.h>
using namespace std;
mt19937_64 rnd;
const long long maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
const long long base = 1e18;
vector<long long> adj[maxn];
vector<long long> be_gr[maxn];
vector<long long> gr[maxn];
long long v[maxn];
long long val[maxn];
long long cntnw[maxn];
long long valnw[maxn];
bool ers_gr[maxn];
long long dp[maxn];
long long dp1[maxn];
bool inf[maxn];
long long dd[maxn];
void dfs(long long u) {
  dd[u] = 1;
  dp1[u] = 0;
  for (auto to : adj[u]) {
    if (ers_gr[to]) continue;
    long long nw = val[to];
    for (auto nxt : gr[to]) {
      if (dd[nxt] == 0) {
        dfs(nxt);
      }
      if (inf[nxt] || dd[nxt] == 1) {
        inf[u] = 1;
        break;
      }
      nw += dp1[nxt];
    }
    if (inf[u] == 1) break;
    dp1[u] = max(dp1[u], nw);
  }
  dd[u] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("t.inp", "r")) {
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
  }
  long long m, n;
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> v[i];
    long long len;
    cin >> len;
    while (len--) {
      long long x;
      cin >> x;
      if (x == -1)
        val[i]++;
      else
        gr[i].push_back(x), be_gr[x].push_back(i);
    }
    adj[v[i]].push_back(i);
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  for (int i = 1; i <= n; i++) {
    dp[i] = base;
    for (auto to : adj[i]) {
      if (gr[to].empty() && dp[i] > val[to]) dp[i] = val[to];
    }
    if (dp[i] != base) q.push(make_pair(dp[i], i));
  }
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    if (dp[p.second] != p.first) continue;
    long long u = p.second;
    for (auto to : be_gr[u]) {
      cntnw[to]++;
      valnw[to] += dp[u];
      if (cntnw[to] == gr[to].size()) {
        if (dp[v[to]] > valnw[to] + val[to]) {
          dp[v[to]] = valnw[to] + val[to];
          q.push(make_pair(dp[v[to]], v[to]));
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i] == base) {
      for (auto to : be_gr[i]) ers_gr[to] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!dd[i] && dp[i] != base) {
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i] == base) {
      cout << -1 << " " << -1 << "\n";
    } else {
      if (inf[i])
        cout << min(dp[i], (long long)314000000) << " " << -2 << "\n";
      else
        cout << min(dp[i], (long long)314000000) << " "
             << min(dp1[i], (long long)314000000) << "\n";
    }
  }
}
