#include <bits/stdc++.h>
using namespace std;
namespace SCC {
vector<vector<int>> g, rg, scc, sccg;
vector<int> nodes, vis, who;
int comp, n;
void init(int n_) {
  n = n_;
  g.assign(n + 1, {});
  rg.assign(n + 1, {});
  vis.assign(n + 1, 0);
  nodes.clear();
  who.assign(n + 1, 0);
  comp = 0;
}
void addEdge(int u, int v) {
  g[u].push_back(v);
  rg[v].push_back(u);
}
void dfs1(int u) {
  vis[u] = 1;
  for (int v : g[u]) {
    if (!vis[v]) dfs1(v);
  }
  nodes.push_back(u);
}
void dfs2(int u) {
  who[u] = comp;
  for (int v : rg[u]) {
    if (!who[v]) dfs2(v);
  }
}
void SCC() {
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs1(i);
  }
  reverse(nodes.begin(), nodes.end());
  for (int u : nodes) {
    if (!who[u]) {
      ++comp;
      dfs2(u);
    }
  }
  scc.assign(comp + 1, {});
  for (int i = 1; i <= n; i++) {
    scc[who[i]].push_back(i);
  }
  sccg.assign(comp + 1, {});
  for (int u = 1; u <= n; u++) {
    for (int v : g[u]) {
      if (who[u] != who[v]) {
        sccg[who[u]].push_back(who[v]);
      }
    }
  }
  for (int i = 1; i <= comp; i++) {
    sort(sccg[i].begin(), sccg[i].end());
    sccg[i].erase(unique(sccg[i].begin(), sccg[i].end()), sccg[i].end());
  }
}
}  // namespace SCC
const int N = 1e5 + 100;
const int LIM = 314000000;
int from[N], cost[N];
vector<int> to[N], rules[N], gfrom[N];
int n, m, mn[N], mx[N];
set<int> to_set[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> from[i];
    int k;
    cin >> k;
    while (k--) {
      int v;
      cin >> v;
      if (v == -1)
        cost[i]++;
      else
        to[i].push_back(v), rules[v].push_back(i), to_set[i].insert(v);
    }
    gfrom[from[i]].push_back(i);
  }
  priority_queue<pair<int, int>> cand;
  for (int i = 1; i <= n; i++) mn[i] = LIM + 1;
  for (int i = 1; i <= m; i++) {
    if (to[i].size() == 0)
      cand.push({-cost[i], from[i]}), mn[from[i]] = min(mn[from[i]], cost[i]);
  }
  while (cand.size() > 0) {
    int u = cand.top().second;
    cand.pop();
    for (int idx : rules[u]) {
      if (to_set[idx].find(u) != to_set[idx].end()) {
        to_set[idx].erase(u);
      }
      if (to_set[idx].size() == 0) {
        int v = from[idx];
        int c = cost[idx];
        for (int w : to[idx]) {
          c += mn[w];
          c = min(c, LIM);
        }
        if (c < mn[v]) {
          mn[v] = c;
          cand.push({-mn[v], v});
        }
      }
    }
  }
  vector<int> vis(n + 1);
  for (int i = 1; i <= n; i++) {
    if (mn[i] == LIM + 1) {
      mn[i] = mx[i] = -1;
    } else {
      vis[i] = true;
    }
  }
  SCC::init(n);
  for (int i = 1; i <= m; i++) {
    bool f = vis[from[i]];
    for (int v : to[i]) {
      f &= vis[v];
    }
    if (f)
      for (int v : to[i]) SCC::addEdge(from[i], v);
  }
  SCC::SCC();
  for (int i = n - 1; i >= 0; i--) {
    int u = SCC::nodes[i];
    if (vis[u] == false) continue;
    int id = SCC::who[u];
    if (SCC::scc[id].size() > 1) {
      mx[u] = -2;
      continue;
    }
    for (int v : SCC::g[u]) {
      if (mx[v] == -2) {
        mx[u] = -2;
        break;
      }
    }
    if (mx[u] == -2) continue;
    for (int idx : gfrom[u]) {
      bool f = vis[from[idx]];
      int cur = cost[idx];
      for (int v : to[idx]) {
        f &= vis[v];
        cur += mx[v];
        cur = min(cur, LIM);
      }
      if (f) {
        mx[u] = max(mx[u], cur);
        bool self_loop = false;
        for (int v : to[idx]) {
          if (v == u) {
            self_loop = true;
          }
        }
        if (self_loop) {
          mx[u] = -2;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << mn[i] << " " << mx[i] << "\n";
  }
  return 0;
}
