public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        while (true) {
            int n = nextInt();
            int m = nextInt();
            if (n + m == 0) {
                break;
            }
            DisjointSet ds = new DisjointSet(n);
            for (int i = 0; i < n; i++) {
                ds.makeSet(i);
            }
            ds.rank[0] = n + 1;
            for (int i = 0; i < m; i++) {
                int p = nextInt();
                int[] arr = new int[p];
                for (int j = 0; j < p; j++) {
                    arr[j] = nextInt();
                }
                for (int j = 1; j < p; j++) {
                    ds.union(arr[j], arr[j - 1]);
                }
            }
            int result = 1;
            int suspect = ds.find(0);
            for (int i = 1; i < n; i++) {
                if (ds.find(i) == suspect) {
                    result++;
                }
            }
            pw.println(result);
            pw.flush();
        }
        pw.close();
    }