#include <iostream>
#include <fstream>
#include <bitset>
#include <vector>
using namespace std;

const int MAXN = 100;
vector<bool> test_results;
vector<bitset<MAXN> > tests; 
bitset<MAXN> false_tests;
bitset<MAXN> true_tests;

int main() 
{
	ifstream in("disease.in");
	ofstream out("disease.out");
	
	size_t n, m;
	in >> n >> m;

	tests.resize(m);

	size_t cur_bit;
	for (size_t i = 0; i < m; i++)
	{
		for (size_t j = 0; j < n; j++) 
		{
			in >> cur_bit;
			tests[i].set(j, cur_bit != 0);
		}

		in >> cur_bit;
		if (cur_bit == 0) 
			false_tests |= tests[i];

		test_results.push_back(cur_bit != 0);
	}

	for (size_t i = 0; i < test_results.size(); i++)
	{
		if (test_results[i]) 
		{
			tests[i] &= ~false_tests;
			int cnt = tests[i].count();
			if (cnt == 0) {
				out << "Incorrect\n";
				return 0;
			} else if (cnt == 1) 
				true_tests |= tests[i];
		}
	}

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

	out << bad << ' ';
	for (size_t i = 0; i < n; i++)
		if (false_tests[i])
			out << i + 1 << ' ';
	out << '\n';

	out << good << ' ';
	for (size_t i = 0; i < n; i++)
		if (true_tests[i])
			out << i + 1 << ' ';
	out << '\n';

	out << n - bad - good << ' ';
	for (size_t i = 0; i < n; i++)
		if (!true_tests[i] && !false_tests[i])
			out << i + 1 << ' ';
	out << '\n';
	
	return 0;
}