#include <bits/stdc++.h>
using namespace std;
int arr[100005] = {0};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int count;
    cin >> count;
    vector<int> temp(count);
    for (int j = 0; j < count; j++) {
      int temp1;
      cin >> temp1;
      temp.push_back(temp1);
    }
    for (int j = 0; j < count; j++) {
      if (j == count - 1)
        arr[temp[j]] = -1;
      else
        arr[temp[j]] = temp[j + 1];
    }
  }
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
  for (int i = 1; i <= n; i++) {
  }
  return 0;
}
