#include <bits/stdc++.h>   using namespace std;   int m, n, arr[2000][2000], temp[2000][2000];   char ctrl(int i) {     for (int j = 1; j <= n; j++)       if (arr[i][j] and arr[i][j] != temp[i][j]) return 0;     return 1;   }   char solve(int a, int b, int c, int d, int ttt = 0) {     if (ttt) ttt = 3;     for (int i = 1; i <= m; i++) {       if (i & 1) {         for (int j = 1; j <= n; j++)           if (j & 1)             temp[i][j] = a;           else             temp[i][j] = b;         if (ctrl(i)) continue;         for (int j = 1; j <= n; j++)           if (j & 1)             temp[i][j] = b;           else             temp[i][j] = a;         if (ctrl(i)) continue;         return 0;       } else {         for (int j = 1; j <= n; j++)           if (j & 1)             temp[i][j] = c;           else             temp[i][j] = d;         if (ctrl(i)) continue;         for (int j = 1; j <= n; j++)           if (j & 1)             temp[i][j] = d;           else             temp[i][j] = c;         if (ctrl(i)) continue;         return 0;       }     }     while (ttt--) {       for (int i = 1; i <= m; i++)         for (int j = 1; j <= n; j++) arr[j][m - i + 1] = temp[i][j];       swap(m, n);       for (int i = 1; i <= m; i++)         for (int j = 1; j <= n; j++) temp[i][j] = arr[i][j];     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) cout << temp[i][j];       cout << endl;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> m >> n;     char c;     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) {         cin >> c;         arr[i][j] = c -  0 ;       }     if (solve(1, 2, 3, 4)) return 0;     if (solve(1, 3, 2, 4)) return 0;     if (solve(1, 4, 2, 3)) return 0;     if (solve(2, 3, 1, 4)) return 0;     if (solve(2, 4, 1, 3)) return 0;     if (solve(3, 4, 1, 2)) return 0;     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) temp[j][m - i + 1] = arr[i][j];     swap(m, n);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) arr[i][j] = temp[i][j];     if (solve(1, 2, 3, 4, 1)) return 0;     if (solve(1, 3, 2, 4, 1)) return 0;     if (solve(1, 4, 2, 3, 1)) return 0;     if (solve(2, 3, 1, 4, 1)) return 0;     if (solve(2, 4, 1, 3, 1)) return 0;     if (solve(3, 4, 1, 2, 1)) return 0;     cout << 0 << endl;   }   