#include <bits/stdc++.h> 
#include <unistd.h>


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

using namespace std;

char mat[10][10], matOrig[10][10];
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] == 'n' || 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;	
				
	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++;
			}
		}
	}
		
	int jj = j+1;
	while((!cifra(i, jj) && mat[i][jj] != '#') && jj < m) mat[i][jj++] = 'x'; 			
	jj = j-1;
	while((!cifra(i, jj) && mat[i][jj] != '#') && jj >= 0) mat[i][jj--] = 'x'; 
			
	int ii = i+1;
	while((!cifra(ii, j) && mat[ii][j] != '#') && ii < n) mat[ii++][j] = 'x'; 
	ii = i-1;
	while((!cifra(ii, j) && mat[ii][j] != '#') && ii >= 0) mat[ii--][j] = 'x'; 
	
	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++;
								}										
							}
							else if(mat[in][jn]-'0' > k+1) return;																																	
						}
					}			
					int dd2 = dodajC(i, j);	
					if(dd2 == -1) mozeNapred = false; 			 
					
					if(!bilo && mozeNapred) bt(i, j+1, josAutica - dd1 - dd2);
					else if(!mozeNapred)
					{
						bool moze = false;
						for(int k = 2; k < 3; k++)
						{
							int in = i + dx[k], jn = j + dy[k];
							if(valid(in, jn) && (mat[in][jn] == '.' || mat[in][jn] == 'x')) moze = true;
						}
						if(!moze) return;
					}							
					
					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;
						}
					}
				}
			}			
		}
	}	
}

bool neMoze = false;

int carCnt = 0;
void jedinaMogucnost()
{
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			// provera je l moze
			if(cifra(i, j) && mat[i][j] != '0')
			{
				int val = mat[i][j] - '0';
				int brSuseda = 0;
				for(int k = 0; k < 4; k++)
					if(valid(i+dx[k],j+dy[k]) && mat[i+dx[k]][j+dy[k]] == '.') brSuseda++;
				if(brSuseda < val)
				{
					neMoze = true;					
					return;
				}
				else if(brSuseda == val)
				{
					int delta = 0;
					for(int k = 0; k < 4; k++)
						if(valid(i+dx[k],j+dy[k]) && mat[i+dx[k]][j+dy[k]] == '.') 
						{
							int val = dodajC(i+dx[k], j+dy[k]);
							if(val == -1)
							{
								neMoze = true;
								return;
							}
							delta += val;
						}
					carCnt -= delta;
					/*stampaj();
					cout << endl << endl;
					sleep(1);*/
					jedinaMogucnost();
					return;
				}
			}
		}
	}
}

void postaviGdeMora()
{
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{			
			if(mat[i][j] == '.')
			{
				int brSuseda = 0;				
				for(int k = 0; k < 4; k++)
					if(valid(i+dx[k],j+dy[k]) && mat[i+dx[k]][j+dy[k]] == '.') brSuseda++;				
				if(brSuseda == 0)
				{
					
					// tu se mora postaviti
					int val = dodajC(i, j);
					if(val != -1)
					{
						carCnt -= val;
					}
					else
					{
						neMoze = true;
						return;
					}					
					/*stampaj();
					sleep(1);*/
				}
			}
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	//freopen("in.txt", "r", stdin);	
	cin.tie(0);	
	cin >> n >> m;
	
	for(int i = 0; i < n; i++)
	{	
		for(int j = 0; j < m; j++) 
		{ 
			cin >> mat[i][j];
			matOrig[i][j] = mat[i][j];			
			if(cifra(i, j) && mat[i][j] != '0') carCnt++;
		}
	}			
	
	postaviGdeMora();
	jedinaMogucnost();		
	
	if(neMoze)
	{
		cout << -1;
		return 0;
	}
	
	bt(0, 0, carCnt);
	if(!bilo) cout << -1;
	return 0; 
}