#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2, class T3 = hash<T1>>
using umap = unordered_map<T1, T2, T3>;
template <class T>
using uset = unordered_set<T>;
template <class T>
using vec = vector<T>;
const long long infll = numeric_limits<long long>::max() >> 1;
const long long inf = 314000000;
const long long N = 1e5 + 1;
long long n, m;
long long lef[N];
long long rig[N];
bool vis[N];
bool stk[N];
bool ans[N];
vec<vec<long long>> adj[N];
vec<long long> wgt[N];
vec<long long> sum[N];
vec<long long> bad[N];
vec<pair<long long, long long>> rev[N];
void input() {
  cin >> m >> n;
  for (long long i = 0; i < m; ++i) {
    long long u;
    cin >> u;
    long long k;
    cin >> k;
    long long w = 0;
    vec<long long> newadj;
    while (k--) {
      long long v;
      cin >> v;
      if (v == -1) {
        w++;
      } else {
        newadj.push_back(v);
        rev[v].push_back({u, (long long)adj[u].size()});
      }
    }
    wgt[u].push_back(w);
    sum[u].push_back(w);
    adj[u].push_back(newadj);
    bad[u].push_back((long long)newadj.size());
  }
}
void update_dijkstra(long long u, long long valx, long long valy) {
  for (pair<long long, long long> p : rev[u]) {
    long long v = p.first;
    long long i = p.second;
    sum[v][i] -= valx;
    sum[v][i] += valy;
  }
}
void update(long long u) {
  for (pair<long long, long long> p : rev[u]) {
    long long v = p.first;
    long long i = p.second;
    bad[v][i]--;
  }
}
void bfs_lef() {
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    bool flag = 0;
    for (int j = 0; j < (long long)adj[i].size(); ++j) {
      flag |= adj[i][j].empty();
    }
    if (flag) {
      vis[i] = 1;
      update(i);
      q.push(i);
    }
  }
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    vis[u] = 1;
    for (pair<long long, long long> p : rev[u]) {
      long long v = p.first;
      long long i = p.second;
      if (!vis[v] && !bad[v][i]) {
        vis[v] = 1;
        update(v);
        q.push(v);
      }
    }
  }
}
void dijkstra_lef() {
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 0; j < (long long)adj[i].size(); ++j) {
      sum[i][j] += (long long)adj[i][j].size() * inf;
    }
  }
  for (long long i = 1; i <= n; ++i) {
    lef[i] = inf;
  }
  auto cmp = [](long long x, long long y) { return lef[x] > lef[y]; };
  priority_queue<long long, vec<long long>, decltype(cmp)> pq(cmp);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < (long long)adj[i].size(); ++j) {
      lef[i] = min(lef[i], sum[i][j]);
    }
    if (lef[i] < inf) {
      update_dijkstra(i, inf, lef[i]);
      pq.push(i);
    }
  }
  while (!pq.empty()) {
    long long u = pq.top();
    pq.pop();
    for (pair<long long, long long> p : rev[u]) {
      long long v = p.first;
      long long i = p.second;
      if (lef[v] > sum[v][i]) {
        long long valx = lef[v];
        long long valy = sum[v][i];
        lef[v] = sum[v][i];
        update_dijkstra(v, valx, valy);
        pq.push(v);
      }
    }
  }
}
bool dfs(int u) {
  if (lef[u] == -1) {
    return ans[u] = 0;
  }
  stk[u] = 1;
  vis[u] = 1;
  for (auto &it : adj[u]) {
    bool flag = 0;
    for (int v : it) {
      if (lef[v] == -1) {
        flag = 1;
      }
    }
    if (flag) {
      continue;
    }
    for (int v : it) {
      if (vis[v]) {
        if (ans[v] || stk[v]) {
          ans[u] = 1;
        }
        continue;
      }
      if (dfs(v)) {
        ans[u] = 1;
      }
    }
  }
  stk[u] = 0;
  return ans[u];
}
long long calc(long long u) {
  if (rig[u] != -2) {
    return rig[u];
  }
  long long res = 0;
  for (int i = 0; i < (long long)adj[u].size(); ++i) {
    long long cur = wgt[u][i];
    bool flag = 0;
    for (int v : adj[u][i]) {
      if (lef[v] == -1) {
        flag = 1;
      }
    }
    if (flag) {
      continue;
    }
    for (int v : adj[u][i]) {
      if (lef[v] == -1) {
        cur = -inf;
        break;
      }
      cur += calc(v);
    }
    res = max(res, cur);
  }
  res = min(res, inf);
  return rig[u] = res;
}
void solve() {
  bfs_lef();
  dijkstra_lef();
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      lef[i] = -1;
    }
  }
  fill(vis, vis + N, 0);
  fill(rig, rig + N, -2);
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (lef[i] == -1) {
      cout << "-1 -1\n";
      continue;
    }
    if (!ans[i]) {
      rig[i] = calc(i);
    }
    cout << lef[i] << " " << rig[i] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
