#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T1, class T2>
inline void print(T1 x1, T2 x2) {
  printsp(x1), println(x2);
}
template <class T1, class T2, class T3>
inline void print(T1 x1, T2 x2, T3 x3) {
  printsp(x1), printsp(x2), println(x3);
}
template <class T1, class T2, class T3, class T4>
inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {
  printsp(x1), printsp(x2), printsp(x3), println(x4);
}
char s[1 << 10][1 << 10];
char ans[1 << 10][1 << 10];
bool solve(int n, int m) {
  for (char a = '1'; a <= '4'; a++) {
    for (char b = a + 1; b <= '4'; b++) {
      char c = '1';
      while (c == a || c == b) c++;
      char d = c + 1;
      while (d == a || d == b) d++;
      int ok = 1;
      for (int i = 0; ok && i < m; i++) {
        char ch[2];
        if (i & 1)
          ch[0] = c, ch[1] = d;
        else
          ch[0] = a, ch[1] = b;
        int f1 = 1, f2 = 1;
        for (int j = 0; j < n; j++) {
          if (s[j][i] > '0' && s[j][i] != ch[j & 1]) f1 = 0;
          if (s[j][i] > '0' && s[j][i] != ch[~j & 1]) f2 = 0;
        }
        if (f1)
          for (int j = 0; j < n; j++) ans[j][i] = ch[j & 1];
        else if (f2)
          for (int j = 0; j < n; j++) ans[j][i] = ch[~j & 1];
        else
          ok = 0;
      }
      if (ok) return true;
    }
  }
  return false;
}
int main() {
  int n, m;
  gn(n, m);
  for (int i = 0; i < n; i++) scanf(" "), gets(s[i]);
  if (solve(n, m))
    for (int i = 0; i < n; i++) puts(ans[i]);
  else {
    for (int i = max(n, m); i--;)
      for (int j = i; j--;) swap(s[i][j], s[j][i]);
    if (solve(m, n)) {
      for (int i = 0; i < n; i++, puts(""))
        for (int j = 0; j < m; j++) putchar(ans[j][i]);
    } else
      puts("0");
  }
  return 0;
}
