#include <iostream>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <cstring>

#define all(x) (x).begin(),(x).end()

using namespace std;

const int nmax = 1e3;
const int mmax = 1e2;

char s[2 * nmax][2 * mmax];
bool add[2 * nmax][2 * mmax];
int n,m;

inline char next(char c)
{
	if (c == '9') 
		return '0';
	else
		return c + 1;
};

inline char prev(char c)
{
	if (c == '0')
		return '9';
	else
		return c - 1;
};

int main()
{
	freopen("calendar.in","r",stdin);
	freopen("calendar.out","w",stdout);
	scanf("%d%d\n",&n,&m);
	for (int i = 0; i < n; i ++)
	{
		gets(s[i]); 
		s[i][m] = 0;
	}
	for (int i = 0; i < n; i ++)
		add[i][m-1] = 1;
	for (int j = m - 1; j >= 0; j --)
	{
		for (int i = 0; i + 1 < n; i ++)
			if (s[i][j] != '*')
				s[i + 1][j] = add[i+1][j] ? next(s[i][j]) : s[i][j];
		for (int i = n - 1; i > 0; i --)
			if (s[i][j] != '*')
				s[i - 1][j] = add[i][j] ? prev(s[i][j]) : s[i][j];
		if (j > 0)
			for (int i = 0; i + 1 < n; i ++)
				if (s[i][j] == '9' && s[i + 1][j] == '0')
					add[i+1][j-1]= 1;
	}
	printf("%s\n", s[0]);
	return 0;
};

