#include <bits/stdc++.h> 

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;
typedef pair<int, int> pi;
typedef long long ll;
typedef pair<ll, ll> pll;

char mat[10][10], matOrig[10][10];
pair<int, int> brKomp[10][10];
int kompCnt = 0;
int n, m;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

bool bilo = false;


bool valid(int i, int j)
{
	return i>=0 && i<n && j>=0 && j<m;
}

bool cifra(int i, int j)
{
	if(!valid(i, j)) return false;
	char c = mat[i][j];
	return c >= '0' && c <= '4';
}


void stampaj()
{
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			if(cifra(i, j) || mat[i][j] == 'x')
				cout << matOrig[i][j];
			else
				cout << mat[i][j];
		}
		cout << endl;
	}
}

bool proveriValidnost()
{
	for(int i = 0; i < n; i++)	
	{	
		for(int j = 0; j < m; j++)	
		{
			if(mat[i][j] == '.' || (cifra(i, j) && mat[i][j] != '0')) return false;			
		}		
	}
	return true;
}

int dodajC(int i, int j)
{
	if(!valid(i, j) || mat[i][j] != '.') return -1;	
			
	// sredjujemo kockice susede
	int delta = 0;	
	mat[i][j] = 'C';
	for(int k = 0; k < 4; k++)
	{
		int in = i + dx[k];
		int jn = j + dy[k];
		if(valid(in, jn))
		{
			if(cifra(in, jn))
			{
				if(mat[in][jn] == '0') return -1;
				else mat[in][jn]--;
				if(mat[in][jn] == '0') delta++;
			}
		}
	}
	
	// oznacavamo polja
	int jj = j+1;
	while((mat[i][jj] == '.' || mat[i][jj] == 'x') && jj < m)
	{
		mat[i][jj] = 'x'; jj++;
	} 
	jj = j-1;
	while((mat[i][jj] == '.' || mat[i][jj] == 'x') && jj >= 0)
	{
		mat[i][jj] = 'x'; jj--;
	} 
	int ii = i+1;
	while((mat[ii][j] == '.' || mat[ii][j] == 'x') && ii < n)
	{
		mat[ii][j] = 'x'; ii++;
	} 
	ii = i-1;
	while((mat[ii][j] == '.' || mat[ii][j] == 'x') && ii >= 0)
	{
		mat[ii][j] = 'x'; ii--;
	} 
	
	return delta;
}

void bt(int ii, int jj, int josAutica)
{
	//cout << ii << " " << jj << " " << josAutica << endl;
	//stampaj();
	//cout << endl;
	//sleep(1);
	if(bilo) return;
	if(josAutica == 0)
	{							
		if(proveriValidnost())		
		{
			stampaj();		
			bilo = true;
		}	
	}
	if(!(ii == n-1 && jj == m))
	{					
		for(int i = ii; i < n; i++)
		{
			int j = 0;
			if(i == ii) j = jj;
			for(; j < m; j++)
			{
				if(mat[i][j] == '.')
				{		
					char staraMat[n][m];					
									
						
					// bekap																
					for(int i = 0; i < n; i++) 
						for(int j = 0; j < m; j++) 
							staraMat[i][j] = mat[i][j];											
					
					int dd1 = 0;
					bool mozeNapred = true;
					for(int k = 0; k < 4; k++)
					{
						int in = i + dx[k], jn = j + dy[k];
						if(cifra(in, jn))
						{
							if(mat[in][jn]-'0' == k+1)
							{
								// postaviti i na preostale
								int dodatno = k, dir = 4-k;
								while(dodatno)
								{
									int inn = in + dx[dir];
									int jnn = jn + dy[dir];
									int dd = dodajC(inn, jnn); 
									if(dd != -1)
									{		
										dd1 += dd;																																														
									}											
									else mozeNapred = false;											
									dodatno--;
									dir++;
								}										
							}																																			
						}
					}			
					int dd2 = dodajC(i, j);	
					if(dd2 == -1) mozeNapred = false; 			 
					
					if(!bilo && mozeNapred) bt(i, j+1, josAutica - dd1 - dd2);							
					
					for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) mat[i][j] = staraMat[i][j];																
					
					bool moraDaGaStavi = false;							
					for(int k = 0; k < 4; k++)
					{
						int in = i + dx[k], jn = j + dy[k];
						if(cifra(in, jn))
						{																									
							if(k < mat[in][jn]-'0') moraDaGaStavi = true;
						}
					}
					if(!bilo && !moraDaGaStavi) bt(i, j+1, josAutica);	
					return;																							
					
				}
				else if(mat[i][j] == 'x')
				{
					for(int k = 0; k < 4; k++)
					{
						int in = i + dx[k], jn = j + dy[k];
						if(cifra(in, jn))
						{
							if(k < mat[in][jn]-'0') return;
						}
					}
				}
			}			
		}
	}	
}

int main()
{
	ios::sync_with_stdio(false);	
	cin.tie(0);	
	cin >> n >> m;
	int carCnt = 0;
	for(int i = 0; i < n; i++)
	{	
		for(int j = 0; j < m; j++) 
		{
			cin >> mat[i][j];
			matOrig[i][j] = mat[i][j];
			brKomp[i][j] = mp(0, 0);
			if(cifra(i, j) && mat[i][j] != '0') carCnt++;
		}
	}			
	bt(0, 0, carCnt);
	if(!bilo) cout << -1;
	return 0; 
}