#include <bits/stdc++.h>
using namespace std;
int a[1111][1111], c[1111][1111];
int b[11];
int m, n;
void output() {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) printf("%d", c[i][j]);
    printf("\n");
  }
}
bool solve() {
  int e = 0, tp;
  bool check;
  for (int i = 1; i <= m; i++) {
    tp = 1;
    for (int j = 1; j <= n; j++) c[i][j] = b[e + tp], tp = 3 - tp;
    check = true;
    for (int j = 1; j <= n; j++)
      if (a[i][j] && (c[i][j] != a[i][j])) check = false;
    if (check) {
      e = 2 - e;
      continue;
    }
    tp = 2;
    for (int j = 1; j <= n; j++) c[i][j] = b[e + tp], tp = 3 - tp;
    check = true;
    for (int j = 1; j <= n; j++)
      if (a[i][j] && (c[i][j] != a[i][j])) check = false;
    if (check) {
      e = 2 - e;
      continue;
    }
    return false;
  }
  return true;
}
bool funny() {
  int e = 0, tp;
  bool check;
  for (int j = 1; j <= n; j++) {
    tp = 1;
    for (int i = 1; i <= m; i++) c[i][j] = b[e + tp], tp = 3 - tp;
    check = true;
    for (int i = 1; i <= m; i++)
      if (a[i][j] && (c[i][j] != a[i][j])) check = false;
    if (check) {
      e = 2 - e;
      continue;
    }
    tp = 2;
    for (int i = 1; i <= m; i++) c[i][j] = b[e + tp], tp = 3 - tp;
    check = true;
    for (int i = 1; i <= m; i++)
      if (a[i][j] && (c[i][j] != a[i][j])) check = false;
    if (check) {
      e = 2 - e;
      continue;
    }
    return false;
  }
  return true;
}
int main() {
  scanf("%d%d\n", &m, &n);
  char x;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) scanf("%c", &x), a[i][j] = int(x) - int('0');
    scanf("\n");
  }
  for (int i = 1; i <= 4; i++) b[i] = i;
  do {
    if (solve()) {
      output();
      return 0;
    }
    if (funny()) {
      output();
      return 0;
    }
  } while (next_permutation(b + 1, b + 4 + 1));
  cout << 0;
  return 0;
}
