import java.io.*;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.StringTokenizer;

public class disease_am {
    public void solve() {
        int n = in.nextInt();
        int m = in.nextInt();

        tests = new BitSet[m];
        false_tests = new BitSet(n);
        true_tests = new BitSet(n);
        test_results = new boolean[m];

        int cur_bit;
        for (int i = 0; i < m; i++) {
            tests[i] = new BitSet(n);
            for (int j = 0; j < n; j++) {
                cur_bit = in.nextInt();
                tests[i].set(j, cur_bit != 0);
            }
            cur_bit = in.nextInt();
            if (cur_bit == 0) {
                false_tests.or(tests[i]);
            }
            test_results[i] = cur_bit != 0;
        }

        for (int i = 0; i < m; i++) {
            if (test_results[i]) {
                tests[i].andNot(false_tests);
                if (tests[i].cardinality() == 0) {
                    out.println("Incorrect");
                    return;
                }
                if (tests[i].cardinality() == 1) {
                    true_tests.or(tests[i]);
                }
            }
        }

        int bad = false_tests.cardinality();
        int good = true_tests.cardinality();

        out.print(bad + " ");
        for (int i = 0; i < n; i++) {
            if (false_tests.get(i)) {
                out.print((i + 1) + " ");
            }
        }
        out.println();

        out.print(good + " ");
        for (int i = 0; i < n; i++) {
            if (true_tests.get(i)) {
                out.print((i + 1) + " ");
            }
        }
        out.println();

        out.print((n - bad - good) + " ");
        for (int i = 0; i < n; i++) {
            if (!false_tests.get(i) && !true_tests.get(i)) {
                out.print((i + 1) + " ");
            }
        }
        out.println();
    }

    BitSet[] tests;
    BitSet false_tests, true_tests;
    boolean[] test_results;

    MyScanner in;
    PrintWriter out;

    public void run() {
        try {
            in = new MyScanner("disease.in");
            out = new PrintWriter("disease.out");
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String name) {
            try {
                br = new BufferedReader(new FileReader(name));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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