#include <bits/stdc++.h>
using namespace std;
int h, w;
char g[1000][1000];
void transpose() {
  swap(h, w);
  for (int i = (0); i < (1000); ++i)
    for (int j = (i + 1); j < (1000); ++j) swap(g[i][j], g[j][i]);
}
int usedmask[2];
int usedlst[2][4], usedcnt[2];
char p[1000][2];
bool samecols() {
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (2); ++j) p[i][j] = '0';
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j)
      if (g[i][j] != '0') {
        int jj = j % 2;
        if (p[i][jj] != '0' && p[i][jj] != g[i][j]) return false;
        p[i][jj] = g[i][j];
      }
  for (int i = (0); i < (h); ++i)
    if (p[i][0] != '0' && p[i][1] != '0' && p[i][0] == p[i][1]) return false;
  for (int i = (0); i < (2); ++i) usedmask[i] = 0, usedcnt[i] = 0;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (2); ++j)
      if (p[i][j] != '0') {
        int ii = i % 2;
        int x = p[i][j] - '0';
        if (usedmask[ii] & (1 << x)) continue;
        usedmask[ii] |= 1 << x;
        usedlst[ii][usedcnt[ii]++] = x;
      }
  if (usedmask[0] & usedmask[1]) return false;
  if (usedcnt[0] > 2 || usedcnt[1] > 2) return false;
  for (int x = (1); x <= (4); ++x)
    if ((usedmask[0] & (1 << x)) == 0 && (usedmask[1] & (1 << x)) == 0)
      for (int i = (0); i < (2); ++i)
        if (usedcnt[i] < 2) {
          usedmask[i] |= 1 << x;
          usedlst[i][usedcnt[i]++] = x;
          break;
        }
  return true;
}
void finish() {
  for (int i = (0); i < (h); ++i) {
    if (p[i][0] == '0')
      p[i][0] =
          '0' + usedlst[i % 2][usedlst[i % 2][0] == p[i][1] - '0' ? 1 : 0];
    if (p[i][1] == '0')
      p[i][1] =
          '0' + usedlst[i % 2][usedlst[i % 2][0] == p[i][0] - '0' ? 1 : 0];
  }
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) g[i][j] = p[i][j % 2];
}
void print() {
  for (int i = (0); i < (h); ++i) {
    for (int j = (0); j < (w); ++j) printf("%c", g[i][j]);
    puts("");
  }
}
void run() {
  scanf("%d%d", &h, &w);
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) scanf(" %c", &g[i][j]);
  if (samecols()) {
    finish();
    print();
    return;
  }
  transpose();
  if (samecols()) {
    finish();
    transpose();
    print();
    return;
  }
  printf("0\n");
}
int main() {
  run();
  return 0;
}
