#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> a;
int go(vector<string> &a) {
  char chs[4] = {'1', '2', '3', '4'};
  int n = a.size();
  int m = a[0].length();
  do {
    vector<string> ans(n, string(m, 0));
    string s[2][2];
    s[0][0].resize(m);
    s[0][1].resize(m);
    s[1][0].resize(m);
    s[1][1].resize(m);
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < m; ++j) {
        s[i][0][j] = chs[2 * i + (j % 2)];
        s[i][1][j] = chs[2 * i + ((j + 1) % 2)];
      }
    }
    int yes = 1;
    for (int i = 0; i < n; ++i) {
      int can = 0;
      for (int k = 0; k < 2; ++k) {
        int ok = 1;
        for (int j = 0; j < m; ++j)
          if (a[i][j] != '0' && a[i][j] != s[i % 2][k][j]) {
            ok = 0;
            break;
          }
        if (ok) {
          ans[i] = s[i % 2][k];
          can = 1;
          break;
        }
      }
      if (!can) {
        yes = 0;
        break;
      }
    }
    if (yes) {
      a = ans;
      return 1;
    }
  } while (next_permutation(chs, chs + 4));
  return 0;
}
void transpose(vector<string> &a) {
  vector<string> res(a[0].length(), string(a.size(), 0));
  for (int i = 0; i < a.size(); ++i)
    for (int j = 0; j < a[0].length(); ++j) res[j][i] = a[i][j];
  a = res;
}
void task() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<string> ans = a;
  if (go(ans)) {
    for (int i = 0; i < n; ++i) cout << ans[i] << "\n";
    return;
  }
  ans = a;
  transpose(ans);
  if (go(ans)) {
    transpose(ans);
    for (int i = 0; i < n; ++i) cout << ans[i] << "\n";
    return;
  }
  cout << 0;
}
int main() {
  task();
  return 0;
}
