#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
int n, m;
int t[N][N];
int _t[N][N];
void transponuj() {
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) {
      swap(t[i][j], t[j][i]);
      swap(_t[i][j], _t[j][i]);
    }
}
int fnd(int i, int c) {
  for (int j = 0; j < N; j++)
    if (t[i][j] == c) return j % 2;
  return -1;
}
bool wyzerowana(int i, int p) {
  for (int j = p; j < N; j += 2)
    if (t[i][j] > 0) return false;
  return true;
}
bool findPos(int i, int c) {
  int p = fnd(i, c);
  if (p >= 0) return p;
  if (p == -1)
    if (wyzerowana(i, 0)) return 0;
  return 1;
}
bool test() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (_t[i][j] && t[i][j] != _t[i][j]) {
        return false;
      };
      if (i > 0 && t[i][j] == t[i - 1][j]) {
        return false;
      };
      if (j > 0 && t[i][j] == t[i][j - 1]) {
        return false;
      };
      if (i > 0 && j > 0 && t[i][j] == t[i - 1][j - 1]) {
        return false;
      };
      if (i > 0 && j < N - 1 && t[i][j] == t[i - 1][j + 1]) {
        return false;
      };
    }
  }
  return true;
}
bool licz() {
  int row[5] = {-2, -1, -1, -1, -1};
  for (int r : {0, 1}) {
    for (int i = r; i < N; i += 2) {
      for (int j = 0; j < N; j++) {
        if (t[i][j] > 0) row[t[i][j]] = r;
      }
    }
  }
  vector<int> colors[2];
  for (int c : {1, 2, 3, 4}) {
    if (row[c] >= 0) colors[row[c]].push_back(c);
  }
  for (int c : {1, 2, 3, 4}) {
    if (row[c] == -1) {
      for (int r : {0, 1})
        if (colors[r].size() < 2) {
          colors[r].push_back(c);
          break;
        }
    }
  }
  for (int i = 0; i < N; i++) {
    for (auto c : colors[i % 2])
      for (int j = findPos(i, c); j < N; j += 2) t[i][j] = c;
  }
  return test();
}
bool run() {
  if (licz()) {
    return 1;
  } else {
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) t[i][j] = _t[i][j];
    transponuj();
    if (!licz())
      return 0;
    else {
      transponuj();
      return 1;
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    static char buf[1002];
    scanf("%s", buf);
    for (int j = 0; j < m; j++) {
      t[i][j] = buf[j] - '0';
      _t[i][j] = t[i][j];
    }
  }
  if (!run())
    printf("0\n");
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) printf("%d", t[i][j]);
      printf("\n");
    }
  }
}
