#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

bool ok(int x, int y){
	if (x < 0 || y < 0 || x > 1 || y > 1)
		return 0;
	return 1;
}

vp d = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
vp l = {{1, 1}, {-1, -1}, {1, -1}, {-1, 1}};

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cerr.tie(nullptr);	

	int n, m;
	cin >> n >> m;

	char a[n][m];
	bool oki = 0, ok1 = 0, ok2 = 0, ok3 = 0;
	for (int i = 0; i < n; ++i){
		string s;
		cin >> s;

		for (int j = 0; j < m; ++j){
			a[i][j] = s[j];

			if (s[j] == '1' || s[j] == '2')
				ok3 = 1;
			if (s[j] != '.')
				oki = 1;
			if (s[j] == '.')
				ok2 = 1;
			if (s[j] == '3' || s[j] == '4')
				ok1 = 1;
		}
	}

	ok3 = ok3 | ok1;
	if (!ok2){
		if (ok3)
			return cout << "-1\n", 0;
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < m; ++j)
				cout << a[i][j];
			cout << '\n';
		}
		return 0;
	}

	if (!oki){
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < m; ++j)
				if (i == j)
					cout << "C";
				else
					cout << ".";
			cout << '\n';
		}
		return 0;
	}

	if (n == 1 && m == 1){
		if (a[0][0] == '.')
			return cout << "C\n", 0;
		if (a[0][0] == '0')
			return cout << "0\n", 0;
		if (a[0][0] >= '1' && a[0][0] <= '4')
			return cout << "-1\n", 0;
		cout << a[0][0] << '\n';
		return 0;
	}

	if (n == 2 && m == 2){

		if (ok1)
			return cout << "-1\n", 0;

		int b = 0;
		pi f = {5, 5}, s = {5, 5};
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < m; ++j){
				if (a[i][j] == '2'){
					b++;

					if (f.first != 5)
						s = {i, j};
					else
						f = {i, j};
				}	
			}
		}

		if (f.first != 5){

			if (s.first != 5){
				int r = abs(f.first-s.first) + abs(f.first-s.first);

				if (r == 1)
					return cout << "-1\n", 0;

				for (auto& i : d){
					int x = f.first + i.first;
					int y = f.second + i.second;

					if (!ok(x, y)) continue;

					if (a[x][y] != '.')
						return cout << "-1\n", 0;
					else
						a[x][y] = 'C';
				}

				for (int i = 0; i < n; ++i){
					for (int j = 0; j < m; ++j){
						cout << a[i][j];
					}
					cout << '\n';
				}
				return 0;
			}

			for (auto& i : d){
					int x = f.first + i.first;
					int y = f.second + i.second;

					if (!ok(x, y)) continue;

					if (a[x][y] != '.')
						return cout << "-1\n", 0;
					else
						a[x][y] = 'C';
			}			

			for (auto& i : l){
				int x = f.first + i.first;
				int y = f.first + i.second;

				if (!ok(x, y)) continue;

				if (a[x][y] != '.' && a[x][y] != '#')
					return cout << "-1\n", 0;
			}

			for (int i = 0; i < n; ++i){
				for (int j = 0; j < m; ++j)
					cout << a[i][j];
				cout << '\n';
			}
			return 0;
		}

		bool test = 0;
		f = {5, 5};
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (a[i][j] == '0'){
					test = 1;
					if (f.first != 5)
						return cout << "-1\n", 0;
					f = {i, j};
				}

		if (test){
			for (auto& i : l){
					int x = f.first + i.first;
					int y = f.first + i.second;

				if (!ok(x, y)) continue;

				if (a[x][y] != '.') return cout << "-1\n", 0;

				a[x][y] = 'C';
			}

			for (int i = 0; i < 2; ++i){
				for (int j = 0; j < 2; ++j)
					cout << a[i][j];
				cout << '\n';
			}
		}

		f = {5, 5};
		s = {5, 5};
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < m; ++j){
				if (a[i][j] == '1'){
					if (f.first != 5)
						s = {i, j};
					else
						f = {i, j};
				}
			}
		}

		if (s.first != 5){
			int r = abs(s.first - f.first) + abs(s.second - f.second);

			int cnt = 0;
			if (r == 2){
				pi tt;
				for (auto& i : d){

					int x = f.first + i.first;
					int y = f.first + i.second;

					if (!ok(x, y)) continue;

					if (a[x][y] == '.'){
						++cnt;
						tt = {x, y};
					}
				}

				if (!cnt || cnt == 2) return cout << "-1\n", 0;
				a[tt.first][tt.second] = 'C';

				for (int i = 0; i < n; ++i){
					for (int j = 0; j < m; ++j)
						cout << a[i][j];
					cout << '\n';
				}
				return 0;
			} else {
				for (auto& i : d){
					int x = f.first + i.first;
					int y = f.first + i.second;

					if (!ok(x, y)) continue;
					if (a[x][y] == '1') continue;

					if (a[x][y] != '.')
						return cout << "-1\n", 0;
					a[x][y] = 'C';
				}


				for (auto& i : d){
					int x = s.first + i.first;
					int y = s.first + i.second;

					if (!ok(x, y)) continue;
					if (a[x][y] == '1') continue;

					if (a[x][y] != '.')
						return cout << "-1\n", 0;
					a[x][y] = 'C';
				}

				for (int i = 0; i < n; ++i){
					for (int j = 0; j < m; ++j)
						cout << a[i][j];
					cout << '\n';				}
			}
			return 0;
		} else {

			int cnt = 0;
			pi tt;
				for (auto& i : d){
					int x = f.first + i.first;
					int y = f.first + i.second;

					if (!ok(x, y)) continue;
					if (a[x][y] == '.'){
						++cnt;
						tt = {x, y};
					}
				}
			if (!cnt || cnt == 2)
				return cout << "-1\n", 0;

			a[tt.first][tt.second] = 'C';
			for (int i = 0 ; i< n; ++i){
				for (int j = 0; j < m; ++j)
					cout << a[i][j];
				cout << '\n';
			}
			return 0;
		}

		if (!ok3){
			int cnt = 0;
			pi f = {5, 5}, s = {5, 5}, tt, w;
			for (int i = 0 ; i< n; ++i){
				for (int j = 0; j < m; ++j){

					if (a[i][j] == '#')
						w = {i, j};

					if (a[i][j] == '.'){
						++cnt;

						if (f.first == 5){
							f = {i, j};
							continue;
						}
						if (s.first == 5){
							s = {i, j};
							continue;
						}
						tt = {i, j};
					}
				}
			}

			if (cnt == 1){
				a[f.first][f.second] = 'C';
				for (int i = 0 ; i< n; ++i){
					for (int j = 0; j < m; ++j)
						cout << a[i][j];
					cout << '\n';
				}
				return 0;		
			}

			if (cnt == 2){
				int r = abs(f.first - s.first) + abs(f.second - s.second);
				if (r == 2){
					a[f.first][f.second] = 'C';
					a[s.first][s.second] = 'C';
					for (int i = 0 ; i< n; ++i){
						for (int j = 0; j < m; ++j)
							cout << a[i][j];
						cout << '\n';
					}
					return 0;
				} else {
					a[f.first][f.second] = 'C';
					for (int i = 0 ; i< n; ++i){
						for (int j = 0; j < m; ++j)
							cout << a[i][j];
						cout << '\n';
					}
					return 0;
				}
			}

			if (cnt == 3){
				for (auto& i : l){
					int x = w.first + i.first;
					int y = w.second + i.second;

					if (!ok(x, y)) continue;

					a[x][y] = 'C';
				}

				for (int i = 0 ; i< n; ++i){
					for (int j = 0; j < m; ++j)
						cout << a[i][j];
					cout << '\n';
				}
				return 0;
			}
		}
	}

	cout << "-1\n";
}