#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<vector<vector<long long> > > a(101000);
vector<vector<pair<long long, long long> > > t(101000);
vector<vector<long long> > s(101000), c(101000), s1(101000);
vector<long long> w(101000);
long long MX = 314000000;
int main() {
  ios::sync_with_stdio(0);
  long long n, m;
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    long long p, x;
    cin >> p;
    long long k;
    cin >> k;
    vector<long long> nw;
    for (int j = 0; j < k; j++) {
      cin >> x;
      nw.push_back(x - 1);
    }
    a[p - 1].push_back(nw);
    s[p - 1].push_back(0);
    s1[p - 1].push_back(0);
    c[p - 1].push_back(0);
    for (int j = 0; j < a[p - 1][a[p - 1].size() - 1].size(); j++)
      if (a[p - 1][a[p - 1].size() - 1][j] != -2) {
        t[a[p - 1][a[p - 1].size() - 1][j]].push_back(
            make_pair(p - 1, a[p - 1].size() - 1));
        s[p - 1][s[p - 1].size() - 1]++;
        s1[p - 1][s[p - 1].size() - 1]++;
      } else
        c[p - 1][c[p - 1].size() - 1]++;
  }
  long long best[n];
  set<pair<long long, long long> > now;
  for (int i = 0; i < n; i++) {
    best[i] = 1e15;
    for (int j = 0; j < s[i].size(); j++)
      if (s[i][j] == 0) {
        best[i] = min(best[i], c[i][j]);
        now.insert(make_pair(c[i][j], i));
      }
  }
  bool us[n];
  for (int i = 0; i < n; i++) us[i] = false;
  while (now.size() > 0) {
    pair<long long, long long> nw = *now.begin();
    now.erase(now.begin());
    int v = nw.second;
    if (us[v]) continue;
    us[v] = true;
    for (int i = 0; i < t[v].size(); i++) {
      s[t[v][i].first][t[v][i].second]--;
      if (s[t[v][i].first][t[v][i].second] == 0) {
        long long sum = c[t[v][i].first][t[v][i].second];
        for (int j = 0; j < a[t[v][i].first][t[v][i].second].size(); j++)
          if (a[t[v][i].first][t[v][i].second][j] != -2) {
            sum += best[a[t[v][i].first][t[v][i].second][j]];
            sum = min(sum, MX);
          }
        if (best[t[v][i].first] > sum) {
          best[t[v][i].first] = sum;
          now.insert(make_pair(sum, t[v][i].first));
        }
      }
    }
  }
  vector<vector<long long> > nw;
  for (int i = 0; i < n; i++) s[i] = s1[i];
  long long mx[n];
  queue<long long> q;
  for (int i = 0; i < n; i++) {
    mx[i] = 0;
    w[i] = s[i].size();
    for (int j = 0; j < s[i].size(); j++)
      if (s[i][j] == 0)
        w[i]--;
      else {
        for (int v = 0; v < a[i][j].size(); v++)
          if (a[i][j][v] >= 0)
            if (best[a[i][j][v]] > MX) {
              w[i]--;
              break;
            }
      }
    if (w[i] == 0) {
      q.push(i);
      long long nw = 0;
      for (int j = 0; j < s[i].size(); j++) {
        bool ok = true;
        for (int v = 0; v < a[i][j].size(); v++)
          if (a[i][j][v] >= 0)
            if (best[a[i][j][v]] > MX) {
              ok = false;
              break;
            }
        if (ok) nw = min(MX, max(nw, c[i][j]));
      }
      mx[i] = nw;
    }
  }
  for (int i = 0; i < n; i++) us[i] = false;
  while (q.size() > 0) {
    long long v = q.front();
    q.pop();
    if (best[v] > MX) continue;
    us[v] = true;
    if (w[v] == 0) {
      for (int i = 0; i < a[v].size(); i++) {
        long long nw = c[v][i];
        bool ok = true;
        for (int j = 0; j < a[v][i].size(); j++)
          if (a[v][i][j] != -2) {
            nw += mx[a[v][i][j]];
            if (best[a[v][i][j]] > MX) ok = false;
          }
        if (ok) mx[v] = min(MX, max(mx[v], nw));
      }
      for (int i = 0; i < t[v].size(); i++) {
        s[t[v][i].first][t[v][i].second]--;
        if (s[t[v][i].first][t[v][i].second] == 0) {
          w[t[v][i].first]--;
          if (w[t[v][i].first] == 0 && best[t[v][i].first] <= MX)
            q.push(t[v][i].first);
        }
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (best[i] > MX)
      cout << -1 << ' ' << -1 << "\n";
    else {
      if (w[i] > 0) mx[i] = -2;
      cout << best[i] << ' ' << mx[i] << "\n";
    }
}
