#include <bits/stdc++.h>
using namespace std;
struct plan {
  vector<int> mon;
  int dia;
};
vector<plan> v[200008];
vector<int> out[200008];
vector<pair<int, int> > vp[200008];
int n, m;
int dp[200008];
const int inf = 0x3f3f3f3f;
int ceiling = 314000000;
int vis[200008];
pair<int, int> ans[200008];
void dfs(int x) {
  if (vis[x] == 2) return;
  if (vis[x] == 1) {
    dp[x] = inf;
    vis[x] = 2;
    return;
  }
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    plan t = v[x][i];
    int tmp = t.dia;
    int flag = 0;
    for (int j = 0; j < t.mon.size(); j++) {
      if (dp[t.mon[j]] == -1) flag = 1;
    }
    if (flag) continue;
    for (int j = 0; j < t.mon.size(); j++) {
      int ccc = t.mon[j];
      dfs(ccc);
      tmp += dp[ccc];
      if (tmp < inf and tmp > ceiling) tmp = ceiling;
      if (tmp > inf) tmp = inf;
    }
    dp[x] = max(tmp, dp[x]);
    if (dp[x] == inf) break;
  }
  vis[x] = 2;
}
int main() {
  scanf("%d%d", &n, &m);
  swap(n, m);
  while (m--) {
    plan a;
    int x;
    scanf("%d", &x);
    a.dia = 0, a.mon.clear();
    int k;
    scanf("%d", &k);
    while (k--) {
      int t;
      scanf("%d", &t);
      if (t < 0)
        a.dia++;
      else {
        a.mon.push_back(t);
        vp[t].push_back(make_pair(x, v[x].size()));
      }
    }
    v[x].push_back(a);
    out[x].push_back(a.mon.size());
  }
  memset(dp, inf, sizeof(dp));
  set<pair<int, int> > pq;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (out[i][j] == 0) {
        dp[i] = min(dp[i], v[i][j].dia);
      }
    }
    if (dp[i] < inf) pq.insert(make_pair(dp[i], i));
  }
  while (!pq.empty()) {
    int t = (*pq.begin()).second;
    pq.erase(pq.begin());
    for (int i = 0; i < vp[t].size(); i++) {
      pair<int, int> op = vp[t][i];
      out[op.first][op.second]--;
      if (out[op.first][op.second] == 0) {
        plan ccc = v[op.first][op.second];
        int tmp = ccc.dia;
        for (int j = 0; j < ccc.mon.size(); j++) {
          tmp += dp[ccc.mon[j]];
          tmp = min(tmp, ceiling);
        }
        if (dp[op.first] > tmp) {
          pq.erase(make_pair(dp[op.first], op.first));
          dp[op.first] = tmp;
          pq.insert(make_pair(dp[op.first], op.first));
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i] >= inf) dp[i] = -1;
    ans[i].first = dp[i];
    if (dp[i] == -1) {
      ans[i].second = -1;
      vis[i] = 2;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i] == inf) dp[i] = -2;
    ans[i].second = dp[i];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
