#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;
const int MAX = 314000000;
int n, m;
int dis[maxn], tot[maxn], sum[maxn], dp[maxn];
vector<int> have[maxn];
queue<int> q;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
class Edge {
 public:
  int from, l, dia, cur;
  vector<int> mons;
} ed[maxn];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = (1); i <= (n); ++i) dis[i] = INF;
  for (int i = (0); i < (m); ++i) {
    scanf("%d%d", &ed[i].from, &ed[i].l);
    for (int j = (0); j < (ed[i].l); ++j) {
      int v;
      scanf("%d", &v);
      if (!~v) {
        ++ed[i].dia;
        continue;
      }
      ed[i].mons.push_back(v);
      have[v].push_back(i);
    }
    if (!ed[i].mons.size()) {
      dis[ed[i].from] = min(dis[ed[i].from], ed[i].dia);
    }
  }
  for (int i = (1); i <= (n); ++i)
    if (dis[i] != INF) pq.push(make_pair(dis[i], i));
  for (; !pq.empty(); pq.pop()) {
    int u = pq.top().second, d = pq.top().first;
    if (d != dis[u]) continue;
    for (int i = (0); i < (have[u].size()); ++i) {
      int id = have[u][i];
      ++ed[id].cur;
      if (ed[id].cur == ed[id].mons.size()) {
        int v = ed[id].from;
        int w = ed[id].dia;
        for (int j = (0); j < (ed[id].mons.size()); ++j) {
          w += dis[ed[id].mons[j]];
          w = min(w, MAX);
        }
        if (w < dis[v]) {
          dis[v] = w;
          pq.push(make_pair(dis[v], v));
        }
      }
    }
  }
  for (int i = (0); i < (m); ++i) {
    bool ok = true;
    ed[i].cur = 0;
    for (int j = (0); j < (ed[i].mons.size()); ++j)
      ok &= (dis[ed[i].mons[j]] != INF);
    if (ok) ++tot[ed[i].from];
  }
  for (int i = (1); i <= (n); ++i)
    if (dis[i] != INF && !tot[i]) q.push(i);
  for (int i = (0); i < (m); ++i) {
    if (!ed[i].mons.size() && dis[ed[i].from] != INF) {
      int w = ed[i].dia;
      for (int j = (0); j < (ed[i].mons.size()); ++j) {
        w += dis[ed[i].mons[j]];
        w = min(w, MAX);
      }
      dp[ed[i].from] = max(dp[ed[i].from], w);
      --tot[ed[i].from];
      if (!tot[ed[i].from]) {
        q.push(ed[i].from);
      }
    }
  }
  for (; !q.empty(); q.pop()) {
    int u = q.front();
    for (int i = (0); i < (have[u].size()); ++i) {
      int id = have[u][i];
      int v = ed[id].from;
      if (dis[v] != INF) {
        sum[id] += dp[u];
        sum[id] = min(sum[id], MAX);
        ++ed[id].cur;
        if (ed[id].cur == ed[id].mons.size()) {
          dp[v] = max(dp[v], min(MAX, sum[id] + ed[id].dia));
          --tot[v];
          if (!tot[v]) q.push(v);
        }
      }
    }
  }
  for (int i = (1); i <= (n); ++i) {
    if (dis[i] == INF) {
      puts("-1 -1");
    } else {
      printf("%d ", dis[i]);
      if (!tot[i])
        printf("%d", dp[i]);
      else
        printf("-2");
      puts("");
    }
  }
  return 0;
}
