#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int oo = 1e9;
int n, m, cc[N][N];
bool vis[N][N];
char g[N][N];
int fx[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int fy[8] = {1, 0, -1, 0, -1, -1, 1, 1};
void dfs(int i, int j, int color, int rotate) {
  if (i <= 0 || j <= 0 || i > n || j > m) return;
  if (vis[i][j]) return;
  if (!cc[i][j]) cc[i][j] = color;
  vis[i][j] = 1;
  if (rotate) {
    dfs(i + 2, j, color, rotate);
    dfs(i - 2, j, color, rotate);
  } else {
    dfs(i, j + 2, color, rotate);
    dfs(i, j - 2, color, rotate);
  }
}
bool check(int rotate, int a, int b, int c, int d) {
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cc[i][j] = g[i][j] - '0';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (cc[i][j]) dfs(i, j, cc[i][j], rotate);
  if (!rotate) {
    for (int i = 1; i <= n; ++i) {
      set<int> st;
      if (i & 1 == 1)
        st.insert(a), st.insert(b);
      else
        st.insert(c), st.insert(d);
      for (int j = 1; j <= 2; ++j) st.erase(cc[i][j]);
      for (int j = 1; j <= 2; ++j) {
        if (!cc[i][j]) {
          cc[i][j] = *st.begin();
          dfs(i, j, cc[i][j], rotate);
        }
        st.erase(cc[i][j]);
      }
      if (st.size()) return false;
    }
  } else {
    for (int j = 1; j <= m; ++j) {
      set<int> st;
      if (j & 1 == 1)
        st.insert(a), st.insert(b);
      else
        st.insert(c), st.insert(d);
      for (int i = 1; i <= 2; ++i) st.erase(cc[i][j]);
      for (int i = 1; i <= 2; ++i) {
        if (!cc[i][j]) {
          cc[i][j] = *st.begin();
          dfs(i, j, cc[i][j], rotate);
        }
        st.erase(cc[i][j]);
      }
      if (st.size()) return false;
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      for (int k = 0; k < 8; ++k) {
        int newX = fx[k] + i;
        int newY = fy[k] + j;
        if (newX >= 1 && newY >= 1 && newX <= n && newY <= m &&
            cc[i][j] == cc[newX][newY])
          return false;
      }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) scanf("%s", g[i] + 1);
  for (int it = 0; it <= 1; ++it)
    for (int a = 1; a <= 4; ++a)
      for (int b = 1; b <= 4; ++b)
        for (int c = 1; c <= 4; ++c)
          for (int d = 1; d <= 4; ++d) {
            set<int> st;
            st.insert(a), st.insert(b), st.insert(c), st.insert(d);
            if (st.size() == 4) {
              if (!check(it, a, b, c, d)) continue;
              for (int i = 1; i <= n; ++i) {
                for (int j = 1; j <= m; ++j) printf("%d", cc[i][j]);
                puts("");
              }
              return 0;
            }
          }
  puts("0");
  return 0;
}
