#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char a[N][N], b[N][N];
int n, m;
bool solve(int c1, int c2, int l) {
  if (l == n + 1) return 1;
  int c3 = 1;
  while (c3 == c1 || c3 == c2) ++c3;
  int c4 = 10 - c1 - c2 - c3;
  for (int i = 1; i <= m; ++i)
    if (i % 2 == 0)
      b[l][i] = c1 + '0';
    else
      b[l][i] = c2 + '0';
  for (int i = 1; i <= m; ++i)
    if (b[l][i] != a[l][i] && a[l][i] != '0') {
      for (int i = 1; i <= m; ++i)
        if (i % 2 == 0)
          b[l][i] = c2 + '0';
        else
          b[l][i] = c1 + '0';
      for (int i = 1; i <= m; ++i)
        if (b[l][i] != a[l][i] && a[l][i] != '0') return 0;
      return solve(c3, c4, l + 1);
    }
  return solve(c3, c4, l + 1);
}
void change(char a[N][N], char b[N][N]) {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) b[i][j] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) b[j][i] = a[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = 0;
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) a[i][j] = b[i][j];
  swap(n, m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) b[i][j] = 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> (a[i] + 1);
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= 4; ++j)
      if (i != j)
        if (solve(i, j, 1)) {
          for (int i = 1; i <= n; ++i) cout << (b[i] + 1) << '\n';
          return 0;
        }
  change(a, b);
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= 4; ++j)
      if (i != j)
        if (solve(i, j, 1)) {
          change(b, a);
          for (int i = 1; i <= n; ++i) cout << (b[i] + 1) << '\n';
          return 0;
        }
  cout << 0 << '\n';
}
