#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int mod = 1000000007;
int n, m;
const int N = 1005;
char mas[N][N], t[N][N];
char c[4];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    scanf("%s", mas[i]);
  }
  for (int i = 0; i < 4; ++i) {
    c[i] = (char)i + '1';
  }
  do {
    bool go = true;
    for (int j = 0; j < m; ++j) {
      char p[2];
      if (j % 2 == 0) {
        p[0] = c[0], p[1] = c[1];
      } else {
        p[0] = c[2], p[1] = c[3];
      }
      bool succ = false;
      for (int _ = 0; _ < 2; ++_) {
        bool flag = true;
        for (int i = 0; i < n; ++i) {
          if (mas[i][j] != '0' && mas[i][j] != p[i % 2]) {
            flag = false;
            break;
          }
        }
        if (flag == 0) {
          swap(p[0], p[1]);
        } else {
          succ = true;
          break;
        }
      }
      if (succ) {
        for (int i = 0; i < n; ++i) {
          t[i][j] = p[i % 2];
        }
      } else {
        go = false;
        break;
      }
    }
    if (go) {
      for (int i = 0; i < n; ++i) {
        printf("%s\n", t[i]);
      }
      return 0;
    }
  } while (next_permutation(c, c + 4));
  for (int i = 0; i < 4; ++i) {
    c[i] = i + '1';
  }
  do {
    bool go = true;
    for (int i = 0; i < n; ++i) {
      char p[2];
      if (i % 2 == 0) {
        p[0] = c[0], p[1] = c[1];
      } else {
        p[0] = c[2], p[1] = c[3];
      }
      bool succ = false;
      for (int _ = 0; _ < 2; ++_) {
        bool flag = true;
        for (int j = 0; j < m; ++j) {
          if (mas[i][j] != '0' && mas[i][j] != p[j % 2]) {
            flag = false;
            break;
          }
        }
        if (!flag) {
          swap(p[0], p[1]);
        } else {
          succ = true;
          break;
        }
      }
      if (succ) {
        for (int j = 0; j < m; ++j) {
          t[i][j] = p[j % 2];
        }
      } else {
        go = false;
        break;
      }
    }
    if (go) {
      for (int i = 0; i < n; ++i) {
        printf("%s\n", t[i]);
      }
      return 0;
    }
  } while (next_permutation(c, c + 4));
  printf("0\n");
  return 0;
}
