#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int m, n, a[20][20], b[20][20], c[20][20], ans[20][20];

void fff(int x, int y) {
b[x][y] = !b[x][y];
if (x - 1 >= 0) {
b[x - 1][y] = !b[x - 1][y];
}
if (x + 1 < m) {
b[x + 1][y] = !b[x + 1][y];
}
if (y - 1 >= 0) {
b[x][y - 1] = !b[x][y - 1];
}
if (y + 1 < n) {
b[x][y + 1] = !b[x][y + 1];
}
}

int main()
{
while (scanf("%d %d", &m, &n) == 2) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
}
}
int minf = 1000;
for (int kase = 0; kase < (1<<n); kase++) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
b[i][j] = a[i][j];
}
}
memset(c, 0, sizeof(c));
int cnt = 0;
for (int i = 0; i < n; i++) {
c[0][i] = (1 & (kase>>(n - i - 1)));
if (c[0][i]) {
fff(0, i);
cnt++;
}
}
for (int i = 1; i < m; i++) {
for (int j = 0; j < n; j++) {
if (b[i - 1][j]) {
c[i][j] = 1;
fff(i, j);
cnt++;
}
}
}
bool ok = true;
for (int i = 0; i < n; i++) {
if (b[m - 1][i]) {
ok = false;
break;
}
}
if (ok && cnt < minf) {
minf = cnt;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
ans[i][j] = c[i][j];
}
}
}
}
if (minf == 1000) {
printf("IMPOSSIBLE\n");
}
else {
for (int i = 0; i < m; i++) {
printf("%d", ans[i][0]);
for (int j = 1; j < n; j++) {
printf(" %d", ans[i][j]);
}
printf("\n");
}
}
}
return 0;
}