import javax.annotation.Resource;
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_tl2 {

    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);
            }
        }


        int[][] a = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                Actor first = actors[i];
                Actor second = actors[j];
                int k = Math.min(first.scenes.size(), second.scenes.size());
                a[i][j] = 1000000000;
                a[j][i] = 1000000000;
                for (int x = 0; x < k; x++) {
                    if (!first.scenes.get(x).equals(second.scenes.get(x))) {
                        int y = Math.min(first.scenes.get(x), second.scenes.get(x));
                        a[i][j] = y + 1;
                        a[j][i] = y + 1;
                        break;
                    }
                }
                if (a[i][j] == 1000000000) {
                    if (first.scenes.size() > k) {
                        int y = first.scenes.get(k);
                        a[i][j] = y + 1;
                        a[j][i] = y + 1;
                    }
                    if (second.scenes.size() > k) {
                        int y = second.scenes.get(k);
                        a[i][j] = y + 1;
                        a[j][i] = y + 1;
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            int res = 0;
            for (int j = 0; j < n; j++) {
                if (i != j)
                    res = Math.max(res, a[i][j]);
            }
            if (res == 1000000000) res = 0;
            out.println(res);
        }

    }

    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_tl2().run();
    }

}
