#include <bits/stdc++.h>
using namespace std;
bool check1(int n, int m, vector<vector<char> > &v, vector<vector<char> > &r,
            vector<bool> &res) {
  int i, j;
  vector<bool> b(n, 1);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (v[i][j] != '0') {
        if (r[i % 2][(j % 2) ^ res[i]] != v[i][j] && b[i] &&
            r[i % 2][1 - j % 2] == v[i][j]) {
          res[i] = 1;
        } else if (r[i % 2][(j % 2) ^ res[i]] != v[i][j]) {
          return 0;
        }
        b[i] = 0;
      }
    }
  }
  return 1;
}
bool check2(int n, int m, vector<vector<char> > &v, vector<vector<char> > &r,
            vector<bool> &res) {
  int i, j;
  vector<bool> b(m, 1);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (v[i][j] != '0') {
        if (r[j % 2][(i % 2) ^ res[j]] != v[i][j] && b[j] &&
            r[j % 2][1 - i % 2] == v[i][j]) {
          res[j] = 1;
        } else if (r[j % 2][(i % 2) ^ res[j]] != v[i][j]) {
          return 0;
        }
        b[j] = 0;
      }
    }
  }
  return 1;
}
void print1(int n, int m, vector<vector<char> > &r, vector<bool> &res) {
  int i, j;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cout << r[i % 2][(j % 2) ^ res[i]];
    }
    cout << endl;
  }
}
void print2(int n, int m, vector<vector<char> > &r, vector<bool> &res) {
  int i, j;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cout << r[j % 2][(i % 2) ^ res[j]];
    }
    cout << endl;
  }
}
bool solve(int x, int y, vector<vector<char> > &r, vector<bool> &b, int n,
           int m, vector<vector<char> > &v) {
  if (y == 2) {
    if (x == 1) {
      vector<bool> res(max(n, m));
      if (check1(n, m, v, r, res)) {
        print1(n, m, r, res);
        return 1;
      }
      if (check2(n, m, v, r, res)) {
        print2(n, m, r, res);
        return 1;
      }
    } else {
      if (solve(1, 0, r, b, n, m, v)) {
        return 1;
      }
    }
  } else {
    for (int i = 1; i < 5; ++i) {
      if (b[i]) {
        b[i] = 0;
        r[x][y] = '0' + i;
        if (solve(x, y + 1, r, b, n, m, v)) {
          return 1;
        }
        b[i] = 1;
      }
    }
  }
  return 0;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(0);
  int n, m, i, j, k;
  cin >> n >> m;
  vector<vector<char> > r(2, vector<char>(2)), v(n, vector<char>(m));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cin >> v[i][j];
    }
  }
  vector<bool> b(5, 1);
  if (!solve(0, 0, r, b, n, m, v)) {
    cout << 0 << endl;
  }
  return 0;
}
