#include <bits/stdc++.h>
using namespace std;
ifstream fin("frac1.in");
ofstream fout("frac1.out");
class compare : public std::binary_function<double, double, bool> {
 public:
  compare(double arg = 1e-7) : e(arg) {}
  bool operator()(const double &left, const double &right) const {
    return (abs(left - right) > e) && (left < right);
  }
  double e;
};
inline long long myabs(long long a) { return (a < 0) ? -a : a; }
inline int d_compare(double x, double y) {
  return (fabs(x - y) <= 1e-7) ? 0 : (x > y) ? 1 : -1;
}
inline int mod(long long x, int y) {
  if (y == 0) return x;
  if (x < 0) x = -x;
  if (x >= y) x %= y;
  return x;
}
inline int cmod(int x, int y) {
  if (y == 0) return x;
  if (x < 0) x += (abs(x) / y + 1) * y;
  if (x >= y) x = x % y;
  return x;
}
int Bcount(int mask) {
  int n = 0;
  while (mask) n += ((mask & -mask) != 0), mask &= ~(mask & -mask);
  return n;
}
inline bool Bstate(int mask, int idx) { return (mask & (1 << idx)); }
inline int B1(int mask, int idx) { return mask | (1 << idx); }
inline int B0(int mask, int idx) { return mask & ~(1 << idx); }
inline int drift(int mask, int n) { return mask & ((1 << n) - 1); }
void debugmask(int mask, int n) {
  for (int i = 0; i < n; i++) cout << Bstate(mask, i);
}
int dr[8] = {0, 0, -1, 1, -1, 1, -1, 1}, dc[8] = {-1, 1, 0, 0, 1, -1, -1, 1};
template <typename Ty>
void clear(Ty &q) {
  Ty empty;
  swap(q, empty);
}
bool check1(int n, int m, vector<vector<char> > &v, vector<vector<char> > &r,
            vector<bool> &res) {
  int i, j;
  vector<bool> b(n, 1);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (v[i][j] != '0') {
        if (r[i % 2][(j % 2) ^ res[i]] != v[i][j] && b[i] &&
            r[i % 2][1 - j % 2] == v[i][j]) {
          res[i] = 1;
        } else if (r[i % 2][(j % 2) ^ res[i]] != v[i][j]) {
          return 0;
        }
        b[i] = 0;
      }
    }
  }
  return 1;
}
bool check2(int n, int m, vector<vector<char> > &v, vector<vector<char> > &r,
            vector<bool> &res) {
  int i, j;
  vector<bool> b(m, 1);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      if (v[i][j] != '0') {
        if (r[j % 2][(i % 2) ^ res[j]] != v[i][j] && b[j] &&
            r[j % 2][1 - i % 2] == v[i][j]) {
          res[j] = 1;
        } else if (r[j % 2][(i % 2) ^ res[j]] != v[i][j]) {
          return 0;
        }
        b[j] = 0;
      }
    }
  }
  return 1;
}
void print1(int n, int m, vector<vector<char> > &r, vector<bool> &res) {
  int i, j;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cout << r[i % 2][(j % 2) ^ res[i]];
    }
    cout << endl;
  }
}
void print2(int n, int m, vector<vector<char> > &r, vector<bool> &res) {
  int i, j;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cout << r[j % 2][(i % 2) ^ res[j]];
    }
    cout << endl;
  }
}
bool solve(int first, int second, vector<vector<char> > &r, vector<bool> &b,
           int n, int m, vector<vector<char> > &v) {
  if (second == 2) {
    if (first == 1) {
      vector<bool> res(max(n, m));
      if (check1(n, m, v, r, res)) {
        print1(n, m, r, res);
        return 1;
      }
      if (check2(n, m, v, r, res)) {
        print2(n, m, r, res);
        return 1;
      }
    } else {
      if (solve(1, 0, r, b, n, m, v)) {
        return 1;
      }
    }
  } else {
    for (int i = 1; i < 5; ++i) {
      if (b[i]) {
        b[i] = 0;
        r[first][second] = '0' + i;
        if (solve(first, second + 1, r, b, n, m, v)) {
          return 1;
        }
        b[i] = 1;
      }
    }
  }
  return 0;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(0);
  int n, m, i, j;
  cin >> n >> m;
  vector<vector<char> > r(2, vector<char>(2)), v(n, vector<char>(m));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cin >> v[i][j];
    }
  }
  vector<bool> b(5, 1);
  if (!solve(0, 0, r, b, n, m, v)) {
    cout << 0 << endl;
  }
  return 0;
}
