#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define ford(i, n) for (int i = (int) n - 1; i >= 0; i--)
#define seta(a, b) memset(a, b, sizeof(a))

const int NMAX = 1010;
const int MMAX = 101;

int n, m, cnt[10], power10[MMAX];
char s[NMAX][MMAX], ans[NMAX][MMAX];
int may[MMAX], zn[MMAX], pre[NMAX], good[NMAX][MMAX][10];

void create_ans(int x, int y, int d)
{
	forn(yy, y)
		forn(xx, n)
			ans[xx][yy] = '0' + zn[yy];

	for (int yy = y; yy < m; ++yy)
	{
		int f = d, cnt = power10[m - yy - 1];
		if (yy > y) f = 9;
		for (int xx = x; xx >= 0; xx--)
		{
			if (cnt == 0)
			{
				cnt = power10[m - yy - 1];
				f = (f + 9) % 10;
			}
			cnt--;
			ans[xx][yy] = '0' + f;
		}

		f = d, cnt = 1;
		if (yy > y) f = 9;
		for (int xx = x; xx < n; xx++)
		{
			if (cnt == 0)
			{
				cnt = power10[m - yy - 1];
				f = (f + 1) % 10;
			}
			cnt--;
			ans[xx][yy] = '0' + f;
		}
	}
	
	forn(i, n)
			printf("%s\n", ans[i]);
	cerr << clock() << endl;
	exit(0);
}

void solve(int y, int d)
{
	int now = 0, tmp = d, cnt = 1, jumps = 0;
	forn(i, n)
	{
		if (cnt == 0)
		{
			cnt = power10[m - y - 1], tmp = (tmp + 1) % 10;
			if (tmp == 0) jumps++;
		}
		cnt--;
		pre[i] = tmp;
		if (s[i][y] != '.' && s[i][y] - '0' != pre[i]) now++;
	}
	forn(x, min(power10[m - y], n))
	{
		if (now == 0 && (y == m - 1 || good[x % power10[m - y - 1]][y + 1][9]))
		{
			if (y == 0 || (may[y - 1] && !jumps)) create_ans(x, y, d);
			good[x][y][d] = 1;
		}
		int pos = (x + 1) % power10[m - y - 1];
		while (pos < n)
		{
			if (pos == 0 && pre[pos] == 0) jumps++;
			if (pos == n - 1 && pre[pos] == 0) jumps--;
			if (s[pos][y] != '.' && s[pos][y] - '0' != pre[pos]) now--; 
			pre[pos] = (pre[pos] + 9) % 10;
			if (s[pos][y] != '.' && s[pos][y] - '0' != pre[pos]) now++; 
			pos += power10[m - y - 1];
		}
	}
}

int main()
{
	freopen("calendar.in", "r", stdin);
	freopen("calendar.out", "w", stdout);

	n = 0;
	seta(ans, 0);
	while (scanf("%s", s[n]) > 0)
		n++;
	m = strlen(s[0]);

	power10[0] = 1;
	for (int i = 1; i <= m; ++i)
		if (i <= 9) power10[i] = power10[i - 1] * 10;
		else power10[i] = power10[i - 1];
	forn(yy, m)
	{
		seta(cnt, 0);
		forn(j, n)
			if (s[j][yy] != '.') cnt[s[j][yy] - '0']++;
		int count = 0;
		zn[yy] = 0;
		forn(j, 10)
			if (cnt[j] > 0) count++, zn[yy] = j;
		if (count > 1) may[yy] = 0;
		else may[yy] = 1;
	}
	forn(i, m)
		if (i && !may[i - 1]) may[i] = 0;

	seta(good, 0);
	ford(j, m)
		forn(d, 10)
			solve(j, d);

	cout << "-1" << endl;
	cerr << clock() << endl;

	return 0;
}
