import java.util.*;
import java.io.*;

//import java.math.*;

public class theatre_sp_java implements Runnable {
	public static void main(String[] args) {
		new Thread(new theatre_sp_java()).start();
	}

	@Override
	public void run() {
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	private final String FNAME = "theatre";
	
	class Person implements Comparable<Person> {
		int n, color;

		public Person(int i, int j) {
			n = i;
			color = j;
		}

		@Override
		public int compareTo(Person o) {
			return color - o.color;
		}
	}

	void solve() {
		int n = nextInt();
		int m = nextInt();
		Person[] p = new Person[n];
		for (int i = 0; i < n; i++) {
			p[i] = new Person(i, 0);
		}
		int nc = 1;
		int[] size = new int[n];
		size[0] = n;
		int[] colorans = new int[n];
		for (int i = 0; i < m; i++) {
			int k = nextInt();
			Person[] pp = new Person[k];
			for (int j = 0; j < k; j++) {
				pp[j] = p[nextInt() - 1];
			}
			Arrays.sort(pp);
			int ii = 0;
			while (ii < k) {
				int jj = ii;
				while (jj < k && pp[ii].color == pp[jj].color) {
					jj++;
				}
				if (jj - ii != size[pp[ii].color]) {
					size[pp[ii].color] -= jj - ii;
					if (size[pp[ii].color] == 1) {
						colorans[pp[ii].color] = i + 1;
					}
					size[nc] = jj - ii;
					if (size[nc] == 1) {
						colorans[nc] = i + 1;
					}
					for (int j = ii; j < jj; j++) {
						pp[j].color = nc;
					}
					nc++;
				}
				ii = jj;
			}
		}
		for (int i = 0; i < n; i++) {
			if (size[p[i].color] > 1) {
				out.print("0 ");
			} else {
				out.print(colorans[p[i].color] + " ");
			}
		}
	}
}
