#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
int n, m;
int a[1005][1005];
string s[1005];
int r[4];
bool thoa_ngang() {
  for (int i = (1); i <= (n); ++i) {
    int f[2];
    memset(f, 1, sizeof(f));
    int u = (i & 1), v;
    for (int t = 0; t < (2); ++t) {
      for (int j = (1); j <= (m); ++j) {
        v = ((j & 1) ^ t);
        if (a[i][j] && (a[i][j] != r[u + u + v])) f[t] = 0;
      }
    }
    if (!(f[0] | f[1])) return false;
  }
  return true;
}
void To_ngang() {
  for (int i = (1); i <= (n); ++i) {
    int f[2];
    memset(f, 1, sizeof(f));
    int u = (i & 1), v;
    for (int t = 0; t < (2); ++t) {
      for (int j = (1); j <= (m); ++j) {
        v = ((j & 1) ^ t);
        if (a[i][j] && (a[i][j] != r[u + u + v])) f[t] = 0;
      }
    }
    int t = 0;
    if (!f[0]) t = 1;
    for (int j = (1); j <= (m); ++j) {
      v = ((j & 1) ^ t);
      a[i][j] = r[u + u + v];
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) printf("%d", a[i][j]);
    printf("\n");
  }
}
bool thoa_doc() {
  for (int j = (1); j <= (m); ++j) {
    int f[2];
    memset(f, 1, sizeof(f));
    int u = (j & 1), v;
    for (int t = 0; t < (2); ++t) {
      for (int i = (1); i <= (n); ++i) {
        v = ((i & 1) ^ t);
        if (a[i][j] && (a[i][j] != r[u + u + v])) f[t] = 0;
      }
    }
    if (!(f[0] | f[1])) return false;
  }
  return true;
}
void To_doc() {
  for (int j = (1); j <= (m); ++j) {
    int f[2];
    memset(f, 1, sizeof(f));
    int u = (j & 1), v;
    for (int t = 0; t < (2); ++t) {
      for (int i = (1); i <= (n); ++i) {
        v = ((i & 1) ^ t);
        if (a[i][j] && (a[i][j] != r[u + u + v])) f[t] = 0;
      }
    }
    int t = 0;
    if (!f[0]) t = 1;
    for (int i = (1); i <= (n); ++i) {
      v = ((i & 1) ^ t);
      a[i][j] = r[u + u + v];
    }
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (m); ++j) printf("%d", a[i][j]);
    printf("\n");
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> s[i];
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      a[i][j] = s[i - 1][j - 1] - '0';
    }
  for (int i = 0; i < (4); ++i) r[i] = i + 1;
  do {
    if (thoa_ngang()) {
      To_ngang();
      return 0;
    }
    if (thoa_doc()) {
      To_doc();
      return 0;
    }
  } while (next_permutation(r, r + 4));
  cout << 0;
  return 0;
}
