#include <bits/stdc++.h>
using namespace std;
int n, m;
const int max_n = 1000 + 10;
char cl[max_n][max_n];
int cnt[max_n][5];
const char comb[6][4] = {{1, 2, 3, 4}, {1, 3, 2, 4}, {1, 4, 2, 3},
                         {2, 3, 1, 4}, {2, 4, 1, 3}, {3, 4, 1, 2}};
int Time = 2;
void sWap() {
  for (int i = 0; i < max(m, n); i++)
    for (int j = i + 1; j < max(m, n); j++) swap(cl[i][j], cl[j][i]);
  swap(n, m);
}
bool can(int st, int a, int b, int c, int d) {
  for (int i = st; i < n; i += 2)
    if (cnt[i][c] != -1 || cnt[i][d] != -1)
      return false;
    else if (cnt[i][a] == 2 || cnt[i][b] == 2)
      return false;
    else if (cnt[i][a] == cnt[i][b] && cnt[i][a] != -1)
      return false;
  return true;
}
void fill(int st, int a, int b) {
  for (int i = st; i < n; i += 2) {
    int r, t;
    if (cnt[i][a] == -1 && cnt[i][b] == -1) {
      r = a;
      t = b;
    } else if (cnt[i][a] == -1) {
      r = (cnt[i][b] ? a : b);
      t = (cnt[i][b] ? b : a);
    } else {
      r = (cnt[i][a] ? b : a);
      t = (cnt[i][a] ? a : b);
    }
    for (int j = 0; j < m; j++) cl[i][j] = (j % 2 ? t : r) + '0';
  }
}
bool find(int a, int b, int c, int d) {
  if (!can(0, a, b, c, d) || !can(1, c, d, a, b)) return false;
  fill(0, a, b);
  fill(1, c, d);
  if (!Time) sWap();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << cl[i][j];
    cout << endl;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> cl[i][j];
  while (Time--) {
    memset(cnt, -1, sizeof cnt);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (cl[i][j] > '0') {
          int color = cl[i][j] - '0';
          if (cnt[i][color] == -1)
            cnt[i][color] = j % 2;
          else if (cnt[i][color] != j % 2)
            cnt[i][color] = 2;
        }
    for (int k = 0; k < 6; k++)
      if (find(comb[k][0], comb[k][1], comb[k][2], comb[k][3]) ||
          find(comb[k][2], comb[k][3], comb[k][0], comb[k][1]))
        return 0;
    sWap();
  }
  cout << 0 << endl;
  return 0;
}
