#include <bits/stdc++.h>
using namespace std;

int n, m;
char grid[10][10];
map<pair<int, int>, bool> used;
map<pair<int, int>, bool> invalid;
inline void take_input() { cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cin >> grid[i][j]; } }
void mark_x() { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (grid[i][j]=='0') { if(i-1>=0 and grid[i-1][j]=='.')invalid[pair<int, int>(i-1, j)]=1; if (j-1>=0 and grid[i][j-1]=='.')invalid[pair<int, int>(i, j-1)]=1; if (j+1<=m and grid[i][j+1]=='.')invalid[pair<int, int>(i, j+1)]=1; if (i+1<=n and grid[i+1][j]=='.')invalid[pair<int, int>(i+1, j)]=1; } } } }
void mark_c_x(int a, int b)
{
	for (int j = b+1; j < m; ++j) 
	{
	 	if (grid[a][j]=='.' or grid[a][j]=='X') grid[a][j]='X'; else break; 
	}
	for (int j = b-1; j>=0; --j)
	{
		if (grid[a][j]=='.' or grid[a][j]=='X') grid[a][j]='X'; else break;
	}
	for (int i = a+1; i < n; ++i) 
	{ 
		if (grid[i][b]=='.' or grid[i][b]=='X') grid[i][b]='X'; else break; 
	}
	for (int i = a-1; i>=0; --i)
	{
		if (grid[i][b]=='.' or grid[i][b]=='X') grid[i][b]='X'; else break;
	}
}

bool rook_update()
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (isdigit(grid[i][j]) and grid[i][j]!='0' and !used[pair<int, int>(i, j)])
			{
				int x = grid[i][j]-'0';
				if (i-1>=0 and grid[i-1][j]=='.' and !invalid[pair<int, int>(i-1, j)])  x--; 
				if (i+1<n and grid[i+1][j]=='.' and !invalid[pair<int, int>(i+1, j)]) x--;
				if (j-1>=0 and grid[i][j-1]=='.' and !invalid[pair<int, int>(i, j-1)])  x--;
				if (j+1<m and grid[i][j+1]=='.' and !invalid[pair<int, int>(i, j+1)]) x--;					

				if (i-1>=0 and grid[i-1][j]=='C')  x--; 
				if (i+1<n and grid[i+1][j]=='C') x--;
				if (j-1>=0 and grid[i][j-1]=='C')  x--;
				if (j+1<m and grid[i][j+1]=='C') x--;	
				if (x==0)
				{
					used[pair<int, int>(i, j)] = 1;
					if (i-1>=0 and grid[i-1][j]=='.') { grid[i-1][j]='C'; mark_c_x(i-1, j); }
					if (i+1<n and grid[i+1][j]=='.') { grid[i+1][j]='C'; mark_c_x(i+1, j); }
					if (j-1>=0 and grid[i][j-1]=='.') { grid[i][j-1]='C'; mark_c_x(i, j-1); }
					if (j+1<m and grid[i][j+1]=='.') { grid[i][j+1]='C'; mark_c_x(i, j+1); }
					return rook_update();
				}
				if (x>0) return 0; 		//invalid grid
			}
		}
	}
	return 1;
}

vector<pair<int, int>> changed;

void reset()
{
	for (int i = 0; i < changed.size(); ++i)
	{
		grid[changed[i].first][changed[i].second] = '.';
	}
	changed.clear();
}

void mark_c_x_monitor(int a, int b)
{
	for (int j = b+1; j < m; ++j) 
	{
	 	if (grid[a][j]=='.') {grid[a][j]='X'; changed.push_back(pair<int, int>(a, j));} else if (grid[a][j]!='X') break; 
	}
	for (int j = b-1; j>=0; --j)
	{
		if (grid[a][j]=='.') {grid[a][j]='X'; changed.push_back(pair<int, int>(a, j));} else if (grid[a][j]!='X')break;
	}
	for (int i = a+1; i < n; ++i) 
	{ 
		if (grid[i][b]=='.') {grid[i][b]='X'; changed.push_back(pair<int, int>(i, b));} else if (grid[i][b]!='X')break; 
	}
	for (int i = a-1; i>=0; --i)
	{
		if (grid[i][b]=='.') {grid[i][b]='X'; changed.push_back(pair<int, int>(i, b));} else if (grid[i][b]!='X')break;
	}
}

int skip = 0;

bool gap_fill()
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (grid[i][j]=='.' and !invalid[pair<int,int>(i,j)] and !skip)
			{
				grid[i][j]='C';
				changed.push_back(pair<int, int>(i, j));
				mark_c_x_monitor(i, j);
				return 1;
			}
			else if (grid[i][j]=='.' and skip) { --skip; }
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (grid[i][j]=='.' and invalid[pair<int,int>(i,j)])
			{
				reset();
				++skip;
				return 1;
			}
		}
	}
	return 0;
}

void sol_print()
{
	for (int i = 0;  i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (grid[i][j]=='X') { cout << '.'; continue; }
			cout << grid[i][j];
		}
		cout << '\n';
	}
}

int main()
{	
	take_input();
	mark_x();
	if (!rook_update()) { cout << -1 << endl; return 0; }
	// dots left
	while(1) 
	{ 
		if (!gap_fill()) break; 
	}
	sol_print();
	return 0;
}