#include <bits/stdc++.h>
using namespace std;
const int VERYBIG = 314000000;
const int INF = VERYBIG + 1;
const int MAXN = 100010;
const int MAXM = 100010;
const int TUNVISITED = 0;
const int TVISITING = 1;
const int TVISITED = 2;
int N, M;
vector<int> DEPOS[MAXM];
int RID[MAXM], CDIA[MAXM];
int minsdia[MAXN], cntpend[MAXM], cntnowsum[MAXM];
vector<int> OCCUR[MAXN], WAYS[MAXN];
set<pair<int, int> > SPII;
int maxsdia[MAXN];
int Statu[MAXN];
void DFS(int x) {
  maxsdia[x] = 0;
  Statu[x] = TVISITING;
  for (vector<int>::iterator it = WAYS[x].begin(); it != WAYS[x].end(); it++) {
    int S = CDIA[*it];
    bool REMOVED = false;
    for (vector<int>::iterator iit = DEPOS[*it].begin();
         iit != DEPOS[*it].end(); iit++) {
      if (minsdia[*iit] == INF) {
        REMOVED = true;
        break;
      }
      if (Statu[*iit] == TVISITING)
        S = INF;
      else {
        if (Statu[*iit] == TUNVISITED) DFS(*iit);
        if ((S == INF) || (maxsdia[*iit] == INF))
          S = INF;
        else
          S = min(VERYBIG, S + maxsdia[*iit]);
      }
    }
    if (!REMOVED) maxsdia[x] = max(maxsdia[x], S);
  }
  Statu[x] = TVISITED;
}
int main() {
  scanf("%d%d", &M, &N);
  int i;
  for (i = 1; i <= M; i++) {
    int u, l;
    scanf("%d%d", &u, &l);
    RID[i] = u;
    CDIA[i] = 0;
    DEPOS[i].clear();
    for (; l; l--) {
      int s;
      scanf("%d", &s);
      if (s == -1)
        CDIA[i]++;
      else
        DEPOS[i].push_back(s);
    }
  }
  for (i = 1; i <= N; i++) minsdia[i] = INF;
  for (i = 1; i <= M; i++) {
    cntpend[i] = DEPOS[i].size();
    cntnowsum[i] = CDIA[i];
    if (cntpend[i] == 0) minsdia[RID[i]] = min(minsdia[RID[i]], cntnowsum[i]);
  }
  SPII.clear();
  for (i = 1; i <= N; i++) {
    OCCUR[i].clear();
    SPII.insert(make_pair(minsdia[i], i));
  }
  for (i = 1; i <= M; i++)
    for (vector<int>::iterator it = DEPOS[i].begin(); it != DEPOS[i].end();
         it++)
      OCCUR[*it].push_back(i);
  for (i = 1; i <= N; i++) {
    pair<int, int> PII = *SPII.begin();
    SPII.erase(SPII.begin());
    if (PII.first == INF) break;
    for (vector<int>::iterator it = OCCUR[PII.second].begin();
         it != OCCUR[PII.second].end(); it++) {
      cntpend[*it]--;
      cntnowsum[*it] = min(cntnowsum[*it] + PII.first, VERYBIG);
      if ((cntpend[*it] == 0) && (cntnowsum[*it] < minsdia[RID[*it]])) {
        SPII.erase(make_pair(minsdia[RID[*it]], RID[*it]));
        minsdia[RID[*it]] = cntnowsum[*it];
        SPII.insert(make_pair(minsdia[RID[*it]], RID[*it]));
      }
    }
  }
  for (i = 1; i <= N; i++) WAYS[i].clear();
  for (i = 1; i <= M; i++) WAYS[RID[i]].push_back(i);
  for (i = 1; i <= N; i++) Statu[i] = TUNVISITED;
  for (i = 1; i <= N; i++)
    if ((Statu[i] == TUNVISITED) && (minsdia[i] < INF)) DFS(i);
  for (i = 1; i <= N; i++)
    if (minsdia[i] == INF)
      printf("-1 -1\n");
    else if (maxsdia[i] == INF)
      printf("%d -2\n", minsdia[i]);
    else
      printf("%d %d\n", minsdia[i], maxsdia[i]);
}
