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

public class disease_bm {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        boolean[] notInfected = new boolean[n];
        int[][] a = new int[m][n + 1];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n + 1; j++) {
                a[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < m; i++)
            if (a[i][n] == 0) {
                for (int j = 0; j < n; j++)
                    if (a[i][j] == 1)
                        notInfected[j] = true;
            }
        boolean[] important = new boolean[n];
        for (int i = 0; i < m; i++)
            if (a[i][n] == 1) {
                int fi = -1, se = -1;
                for (int j = 0; j < n; j++)
                    if (a[i][j] == 1 && !notInfected[j]) {
                        if (fi == -1) {
                            fi = j;
                        } else {
                            se = j;
                        }
                    }
                if (fi == -1) {
                    out.println("Incorrect");
                    return;
                }
                if (se == -1) {
                    important[fi] = true;
                }
            }
        for (int i = 0; i < n; i++) {
            if (notInfected[i])
                print((i + 1));
        }
        println();
        for (int i = 0; i < n; i++) {
            if (important[i])
                print((i + 1));
        }
        println();
        for (int i = 0; i < n; i++)
            if (!notInfected[i] && !important[i])
                print((i + 1));
        println();
    }
    
    void print(int x) {
        xx.add(x);
    }
    
    ArrayList<Integer> xx = new ArrayList<>();
    
    void println() {
        out.print(xx.size()+" ");
        for (int i = 0; i< xx.size(); i++)
            out.print(xx.get(i) +" ");
        xx.clear();
        out.println();
    }

    void run() {
        try {
            in = new FastScanner(new File("disease.in"));
            out = new PrintWriter(new File("disease.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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