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

public class disease_av {

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

		boolean[][] wasInTest = new boolean[m][n];
		boolean[] positive = new boolean[m];
		int[] countOnes = new int[m];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int x = in.nextInt();
				countOnes[i] += x;
				wasInTest[i][j] = x == 1;
			}
			positive[i] = in.nextInt() == 1;
		}

		List<Integer> harmless = new ArrayList<>(), harmful = new ArrayList<>();
		boolean[] used = new boolean[n];

		for (int i = 0; i < m; i++) {
			if (!positive[i]) {
				for (int j = 0; j < n; j++) {
					if (!used[j] && wasInTest[i][j]) {
						harmless.add(j);
						used[j] = true;
						for (int test = 0; test < m; test++) {
							if (wasInTest[test][j]) {
								countOnes[test]--;
								if (countOnes[test] == 0 && positive[test]) {
									out.println("Incorrect");
									return;
								}
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < m; i++) {
			if (countOnes[i] == 1) {
				int item = 0;
				while (item < n && (!wasInTest[i][item] || used[item])) {
					item++;
				}
				if (item == n){ 
					continue;
				}

				used[item] = true;
				harmful.add(item);
			}
		}

		printList(harmless);
		printList(harmful);

		int remained = n - harmless.size() - harmful.size();
		out.print(remained);
		for (int i = 0; i < n; i++) {
			if (!harmless.contains(i) && !harmful.contains(i)) {
				out.print(" " + (i + 1));
			}
		}
		out.println();
	}

	private void printList(List<Integer> list) {
		out.print(list.size());
		for (int i = 0; i < list.size(); i++) {
			out.print(" " + (list.get(i) + 1));
		}
		out.println();
	}

	FastScanner in;
	PrintWriter out;

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner(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_av().run();
	}
}
