import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

/**
 * To be documented
 *
 * @author Pavel Mavrin
 */
public class theatre_pm_tl {

    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;


    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

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

    private void solve() {
        int n = nextInt();
        int m = nextInt();
        Actor[] actors = new Actor[n];
        for (int i = 0; i < n; i++) {
            actors[i] = new Actor(i);
        }
        for (int i = 0; i < m; i++) {
            int k = nextInt();
            for (int j = 0; j < k; j++) {
                int a = nextInt();
                actors[a - 1].scenes.add(i);
            }
        }

//        Arrays.sort(actors);

        Node root = new Node();
        for (Actor actor : actors) {
            Node current = root;
            int last = -1;
            for (int j : actor.scenes) {
                if (j > last + 1) {
                    current = current.add(0, j - last - 1);
                }
                current = current.add(1, 1);
                last = j;
            }
            if (last < m - 1) {
                current = current.add(0, m - last - 1);
            }
            current.weight++;
            current.number = actor.id;
        }

        int[] res = new int[n];
        root.calculate(res, 0, 0);

        for (int i = 0; i < n; i++) {
            out.println(res[i]);
        }

    }

    class Actor implements Comparable<Actor> {
        int id;
        List<Integer> scenes = new ArrayList<Integer>();

        Actor(int id) {
            this.id = id;
        }

        public int compareTo(Actor actor) {
            for (int i = 0; i < Math.min(scenes.size(), actor.scenes.size()); i++) {
                int a = scenes.get(i);
                int b = actor.scenes.get(i);
                if (a < b) return 1;
                if (a > b) return -1;
            }
            if (scenes.size() > actor.scenes.size()) return 1;
            if (scenes.size() < actor.scenes.size()) return -1;
            return 0;
        }
    }

    class Node {
        Node[] children = new Node[2];
        int[] childrenLength = new int[2];
        int weight;
        int number;

        public Node add(int digit, int length) {
            if (length == 0) {
                return this;
            }
            if (children[digit] == null) {
                Node newNode = new Node();
                children[digit] = newNode;
                childrenLength[digit] = length;
                return newNode;
            }
            if (childrenLength[digit] <= length) {
                return children[digit].add(digit, length - childrenLength[digit]);
            }
            Node middle = new Node();
            middle.children[digit] = children[digit];
            middle.childrenLength[digit] = childrenLength[digit] - length;
            children[digit] = middle;
            childrenLength[digit] = length;
            return middle;
        }

        public void calculate(int[] res, int length, int minLength) {
            for (int i = 0; i < 2; i++) {
                if (children[i] != null) {
                    children[i].calculate(res, length + childrenLength[i], length + 1);
                    weight += children[i].weight;
                    number += children[i].number;
                }
            }
            if (weight == 1) {
                res[number] = minLength;
            }
        }
    }

    private void run() {
        try {
            br = new BufferedReader(new FileReader("theatre.in"));
            out = new PrintWriter("theatre.out");
            solve();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.exit(239);
        }
    }

    public static void main(String[] args) {
        new theatre_pm_tl().run();
    }

}
