#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int num = 0, k = 1;
  while (ch > '9' || ch < '0') k = (ch == '-' ? -1 : k), ch = getchar();
  while (ch <= '9' && ch >= '0') num *= 10, num += ch - 48, ch = getchar();
  return num * k;
}
struct Edge {
  int next, to;
} ed[200000 + 5];
priority_queue<pair<long long, int> > q;
vector<int> H[200000 + 5], G[200000 + 5];
long long ans[200000 + 5], dis[200000 + 5], value[200000 + 5];
bool inq[200000 + 5], vis[200000 + 5];
int k[200000 + 5], last[200000 + 5], to[200000 + 5], n, m, ecnt = 0,
                                                           dep[200000 + 5];
void add(int u, int v) {
  ed[++ecnt].to = v, ed[ecnt].next = last[u], last[u] = ecnt;
}
void getAns(int u) {
  vis[u] = 1, inq[u] = 1;
  for (int i = 0; i < H[u].size(); i++) {
    int x = H[u][i];
    bool flag1 = 0, flag2 = 0;
    for (int j = 0; j < G[x].size(); j++) {
      int v = G[x][j];
      if (ans[v] == -1) {
        flag1 = 1;
        break;
      }
    }
    if (flag1) continue;
    long long sum = value[x];
    for (int j = 0; j < G[x].size(); j++) {
      int v = G[x][j];
      if (inq[v]) {
        flag2 = 1;
        break;
      }
      if (!vis[v]) getAns(v);
      if (ans[v] == -2) {
        flag2 = 1;
        break;
      }
      sum += ans[v];
      sum = min(sum, 314000000ll);
    }
    if (flag2) {
      ans[u] = -2, inq[u] = 0;
      return;
    }
    ans[u] = max(ans[u], sum);
  }
  inq[u] = 0;
}
int main() {
  m = read(), n = read();
  for (int i = 1; i <= n; i++) dis[i] = 314000000ll + 1;
  for (int i = 1; i <= m; i++) {
    to[i] = read(), k[i] = read(), H[to[i]].push_back(i);
    int tmp = k[i];
    for (int j = 1; j <= tmp; j++) {
      int x = read();
      if (x == -1)
        k[i]--, value[i]++;
      else
        add(x, i), G[i].push_back(x);
    }
    if (!k[i])
      if (dis[to[i]] > value[i])
        dis[to[i]] = value[i], q.push(make_pair((-dis[to[i]]), (to[i])));
  }
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = last[u]; i; i = ed[i].next) {
      int v = ed[i].to;
      k[v]--;
      if (!k[v]) {
        long long sum = value[v];
        for (int i = 0; i < G[v].size(); i++)
          sum += dis[G[v][i]], sum = min(sum, 314000000ll);
        if (dis[to[v]] > sum)
          dis[to[v]] = sum, q.push(make_pair((-dis[to[v]]), (to[v])));
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) ans[i] = -1;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (!vis[i] && ans[i] != -1) getAns(i);
  for (int i = 1; i <= n; i++)
    if (ans[i] == -1)
      puts("-1 -1");
    else
      printf("%lld %lld\n", dis[i], ans[i]);
  return 0;
}
