#include <cassert>
#include <cstdio>
#include <cstring>

int main() {
  assert(freopen("disease.in", "r", stdin));
  assert(freopen("disease.out", "w", stdout));

  int n, m;
  assert(scanf("%d%d", &n, &m) == 2);
  int a[m][n], b[m];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++)
      assert(scanf("%d", &a[i][j]) == 1);
    assert(scanf("%d", &b[i]) == 1);
  }

  int neg[n], pos[n], fail = 0;
  memset(neg, 0, sizeof(neg[0]) * n);
  memset(pos, 0, sizeof(pos[0]) * n);
  for (int i = 0; i < m; i++)
    if (!b[i])
      for (int j = 0; j < n; j++)
        if (a[i][j])
          neg[j] = 1;
  for (int i = 0; i < m; i++)
    if (b[i]) {
      int cnt = 0;
      for (int j = 0; j < n; j++)
        if (a[i][j] && !neg[j])
          cnt++;
      if (cnt == 0)
        fail = 1;
      if (cnt == 1)
        for (int j = 0; j < n; j++)
          if (a[i][j] && !neg[j])
            pos[j] = 1;
    }

  if (fail) {
    puts("Incorrect");
    return 0;
  }

  int cnt;
  cnt = 0;
  for (int i = 0; i < n; i++)
    if (neg[i])
      cnt++;
  printf("%d", cnt);
  for (int i = 0; i < n; i++)
    if (neg[i])
      printf(" %d", i + 1);
  puts("");
  cnt = 0;
  for (int i = 0; i < n; i++)
    if (pos[i])
      cnt++;
  printf("%d", cnt);
  for (int i = 0; i < n; i++)
    if (pos[i])
      printf(" %d", i + 1);
  puts("");
  cnt = 0;
  for (int i = 0; i < n; i++)
    if (!pos[i] && !neg[i])
      cnt++;
  printf("%d", cnt);
  for (int i = 0; i < n; i++)
    if (!pos[i] && !neg[i])
      printf(" %d", i + 1);
  puts("");

  return 0;
}

