#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back                     

#define bitset bitset_mklmnklb

#define CNT __builtin_popcount

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;

const int MAXN = 100100;


struct bitset{
   uint v[MAXN/32];
   void copy(bitset* nv){
      memcpy(nv->v,v,sizeof(v));
   }
   int test(int id){
      return !!(v[id>>5] & (1u<<(id&31)));
   }
   void set(int id){
      v[id>>5] |= (1u<<(id&31));
   }
   void reset(int id){
      v[id>>5] &= ~(1u<<(id&31));
   }
   int count(){
      int res = 0;
      for (int i = 0; i < MAXN/32; i++)
        res += CNT(v[i]);
      return res;
   }

   void andwith(bitset* r){
        for (int i = 0; i < MAXN/32; i++)
            v[i] &= r->v[i];
   }

   void andwithnot(bitset* r){
        for (int i = 0; i < MAXN/32; i++)
            v[i] &= ~(r->v[i]);
   }

   int any(){
       for (int i = 0; i < MAXN/32; i++)
           if (v[i])
               return i*32 + __builtin_ctz(v[i]);
       return -1;
   }
   bitset(){
       CNT_B++;
       memset(v,0,sizeof(v));
   }
};

vector<bitset*> v;
vector<int> to;


bitset cur;

int maxtm[MAXN];
int id[MAXN];
int id2[MAXN];
int ans[MAXN];
int act[MAXN];

int n,m;

int main(){
    freopen("theatre.in","r",stdin);
    freopen("theatre.out","w",stdout);
    
    scanf("%d %d",&n,&m);
    
    v.pb(new bitset());
    to.pb(-1);

    for (int i = 0; i < n; i++)
        v[0]->set(i), id[i] = 0, ans[i] = -1;

    maxtm[0] = 0;

    bitset* temp = new bitset();


    for (int i = 0; i < m; i++){
        int k;
        scanf("%d",&k);
        for (int j = 0; j < k; j++){
            scanf("%d",&act[j]);
            --act[j];
            cur.set(act[j]);
        }


        for (int j = 0; j < k; j++){
            int msk = id[act[j]];
            if (to[msk] != -1)
                continue;
            v[msk]->copy(temp);
            v[msk]->andwithnot(&cur);
            temp->andwith(&cur);
            if (v[msk]->count()){
                v.pb(temp);
                to[msk] = (int)v.size()-1;
                to.pb(-1);
                maxtm[msk] = i;
                maxtm[(int)v.size()-1] = i;
                temp = new bitset();
            }
            else {
                swap(v[msk],temp);
                to[msk] = -2;
            }
        }

        for (int j = 0; j < k; j++){
            int msk = id[act[j]];
            if (to[msk] >= 0)
                id2[act[j]] = to[msk];
        }
                                  
        for (int j = 0; j < k; j++){
           to[id[act[j]]] = -1;
           id[act[j]] = id2[act[j]];
        }

        for (int j = 0; j < k; j++)
           cur.reset(act[j]);        
    }

    for (int i = 0; i < (int)v.size(); i++){
        if (v[i]->count() == 1){  
            ans[v[i]->any()] = maxtm[i];
        }
    }

    for (int i = 0; i < n; i++)
        printf("%d ",ans[i]+1);

    return 0;
}

