#include <stdio.h>

char a[12][12];
char at[12][12];
char pop[12][12];

struct topovi
{
	int i;
	int j;
};

topovi top[144];

void smanjiKocku(char a[12][12], int i, int j)
{
	for (int q = -1; q <= 1; q++)
	{
		for (int w = -1; w <= 1; w++)
		{
			if (q - w == 0 || q - w == 2 || q - w == -2)
			{
				continue;
			}
			if (a[i + q][j + w] > '0' && a[i + q][j + w] <= '4')
			{
				a[i + q][j + w] = (char)((int)a[i + q][j + w] - 1);
			}
		}
	}
	return;
}

void povecajKocku(char a[12][12], int i, int j)
{
	for (int q = -1; q <= 1; q++)
	{
		for (int w = -1; w <= 1; w++)
		{
			if (q - w == 0 || q - w == 2 || q - w == -2)
			{
				continue;
			}
			if (a[i + q][j + w] >= '0' && a[i + q][j + w] <= '4')
			{
				a[i + q][j + w] = (char)((int)a[i + q][j + w] + 1);
			}
		}
	}
	return;
}

bool gotovo(char a[12][12], int n, int m)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][j] > '0' && a[i][j] <= '4')
			{
				return false;
			}
		}
	}
	return true;
}

void ispisiMatricu(char a[12][12], int n, int m)
{
	int br = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i != top[br].i || j != top[br].j)
			{
				printf("%c", at[i][j]);
			}
			else
			{
				printf("%c", 'C');
				br++;
			}
		}
		printf("\n");
	}
}
bool mozeStaviti(char a[12][12], int i, int j, int n, int m)
{
	if (a[i][j] != '.')
	{
		return false;
	}
	for (int q = j + 1; q < m; q++)
	{
		if (a[i][q] == 'C')
		{
			return false;
		}
		if (a[i][q] != '.')
		{
			break;
		}
	}
	for (int q = j - 1; q >= 0; q--)
	{
		if (a[i][q] == 'C')
		{
			return false;
		}
		if (a[i][q] != '.')
		{
			break;
		}
	}
	for (int q = i + 1; q < n; q++)
	{
		if (a[q][j] == 'C')
		{
			return false;
		}
		if (a[q][j] != '.')
		{
			break;
		}
	}
	for (int q = i - 1; q >= 0; q--)
	{
		if (a[q][j] == 'C')
		{
			return false;
		}
		if (a[q][j] != '.')
		{
			break;
		}
	}
	for (int q = -1; q <= 1; q++)
	{
		for (int w = -1; w <= 1; w++)
		{
			if (q - w == 0 || q - w == 2 || q - w == -2)
			{
				continue;
			}
			if (a[i + q][j + w] >= '0' && a[i + q][j + w] <= '4')
			{
				if (a[i + q][j + w] == '0')
				{
					return false;
				}
			}
		}
	}
	return true;
}

bool popunjeno(char a[12][12], int n, int m)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (pop[i][j] == '.')
			{
				return false;
			}
		}
	}
	return true;
}

void vrati(int n, int m)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (pop[i][j] == ',')
			{
				pop[i][j] = '.';
			}
		}
	}
	return;
}

void popuni(int n, int m)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][j] == 'C')
			{
				pop[i][j] = 'C';
				for (int q = j + 1; q < m; q++)
				{
					if (a[i][q] == '.')
					{
						pop[i][q] = ',';
					}
					else
					{
						break;
					}
				}
				for (int q = j - 1; q >= 0; q--)
				{
					if (a[i][q] == '.')
					{
						pop[i][q] = ',';
					}
					else
					{
						break;
					}
				}
				for (int q = i + 1; q < n; q++)
				{
					if (a[q][j] == '.')
					{
						pop[q][j] = ',';
					}
					else
					{
						break;
					}
				}
				for (int q = i - 1; q >= 0; q--)
				{
					if (a[q][j] == '.')
					{
						pop[q][j] = ',';
					}
					else
					{
						break;
					}
				}
			}
		}
	}
	return;
}

void stavljajTopove(char a[12][12], int i, int j, int n, int m, int k)
{
	if (i > n || j > m)
	{
		if (gotovo(a, n, m))
		{
			popuni(n, m);
			if (popunjeno(pop, n, m))
			{
				ispisiMatricu(a, n, m);
				return;
			}
			else
			{
				vrati(n, m);
			}
		}
		a[top[k - 1].i][top[k - 1].j] = '.';
		povecajKocku(a, top[k - 1].i, top[k - 1].j);
		top[k - 1].i = 0;
		top[k - 1].j = 0;
		if (k - 2 >= 0)
		{
			a[top[k - 2].i][top[k - 2].j] = '.';
			int ti = top[k - 2].i;
			int tj = top[k - 2].j;
			povecajKocku(a, top[k - 2].i, top[k - 2].j);
			top[k - 2].i = 0;
			top[k - 2].j = 0;
			if (tj >= m - 1)
			{
				stavljajTopove(a, ti + 1, 0, n, m, k - 2);
			}
			else
			{
				stavljajTopove(a, ti, tj + 1, n, m, k - 2);
			}
		}
		else
		{
			printf("-1");
			return;
		}
	}
	if (j == m)
	{
		i++;
		j = 0;
	}
	if (mozeStaviti(a, i, j, n, m))
	{
		a[i][j] = 'C';
		smanjiKocku(a, i, j);
		top[k].i = i;
		top[k].j = j;
		stavljajTopove(a, i, j + 1, n, m, k + 1);
	}
	else
	{
		stavljajTopove(a, i, j + 1, n, m, k);
	}
}

int main()
{
	int n, m;
	scanf("%d %d\n", &n, &m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m + 1; j++)
		{
			scanf("%c", &a[i][j]);
			at[i][j] = a[i][j];
			pop[i][j] = a[i][j];
		}
	}

	stavljajTopove(a, 0, 0, n, m, 0);
	return 0;
}