#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;
queue<pii> path ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		path.push( a ) ;
		q.pop() ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	while( !path.empty() ) {
		a = path.front() ;
		path.pop() ;
		id[ a.fi ][ a.se ] = mark ;
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		id[ a.fi ][ a.se ] = mark ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
char t[ N ][ N ] ;
bool vis[ N ][ N ] ;
int id[ N ][ N ] ;
int cnt[ N*N ] ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 0 <= x && x < n ) ;
	bool b = ( 0 <= y && y < m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	vis[ x ][ y ] = true ;
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( vis[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] != '.' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	REP( i , n ) {
		scanf( "%s" , t[ i ] ) ;
	}
	REP( i , n ) {
		REP( j , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int mark = i*N + j ;
			int cnt_ = dfs( i , j , mark ) ;
			cnt[ mark ] = cnt_ ;
		}
	}
	REP( i , n ) {
		REP( j , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	REP( i , n ) {
		printf( "%s\n" , t[ i ] ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ 2*N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j - 1 ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		id[ a.fi ][ a.se ] = mark ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N + 1 ][ N + 1 ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;
queue<pii> path ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		path.push( a ) ;
		q.pop() ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	while( !path.empty() ) {
		a = path.front() ;
		path.pop() ;
		cnt[ a.fi ][ a.se ] = cnt_ ;
		id[ a.fi ][ a.se ] = mark ;
	}
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ nx ][ ny ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] != -1 ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

void bfs( int x , int y , int mark ) {
	int cnt_ = 1 ;
	id[ x ][ y ] = mark ;
	queue<pii> q ;
	q.push( { x , y } ) ;
	while( !q.empty() ) {
		pii a = q.front() ;
		q.pop() ;
		REP( d , 4 ) {
			b.fi = x + dir[ d ] ;
			b.se = y + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( id[ b.fi ][ b.se ] != -1 ) continue ;
			id[ b.fi ][ b.se ] = mark ;
			cnt_ ++ ;
			q.push( b ) ;
		}
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( id[ nx ][ ny ] == -1 ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) continue ;
			if( id[ i ][ j ] != -1 ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( i , j , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int bfs( pii st , int mark ) {
	int cnt = 1 ;
	id[ st.fi ][ st.se ] = mark ;
	queue<pii> q ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( id[ b.fi ][ b.se ] ) continue ;
			id[ b.fi ][ b.se ] = mark ;
			cnt ++ ;
			q.push( b ) ;
		}
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] != '.' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j - 1 ;
			int cnt_ = bfs( { i , j } , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;

int bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		id[ a.fi ][ a.se ] = mark ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	return cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( id[ nx ][ ny ] == -1 ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			int cnt_ = bfs( { i , j } , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N + 1 ][ N + 1 ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;
queue<pii> path ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		path.push( a ) ;
		q.pop() ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	while( !path.empty() ) {
		a = path.front() ;
		path.pop() ;
		cnt[ a.fi ][ a.se ] = cnt_ ;
		id[ a.fi ][ a.se ] = mark ;
	}
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ nx ][ ny ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j - 1 ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + 1 ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] != -1 ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] != '.' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) continue ;
			if( id[ i ][ j ] != -1 ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int bfs( pii st , int mark ) {
	int cnt = 1 ;
	id[ st.fi ][ st.se ] = mark ;
	queue<pii> q ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( id[ b.fi ][ b.se ] ) continue ;
			id[ b.fi ][ b.se ] = mark ;
			cnt ++ ;
			q.push( b ) ;
		}
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j - 1 ;
			int cnt_ = bfs( { i , j } , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;
queue<pii> path ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		path.push( a ) ;
		q.pop() ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	while( !path.empty() ) {
		a = path.front() ;
		path.pop() ;
		id[ a.fi ][ a.se ] = mark ;
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int bfs( pii st , int mark ) {
	int cnt = 1 ;
	id[ st.fi ][ st.se ] = mark ;
	queue<pii> q ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( id[ b.fi ][ b.se ] ) continue ;
			id[ b.fi ][ b.se ] = mark ;
			cnt ++ ;
			q.push( b ) ;
		}
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j - 1 ;
			int cnt_ = bfs( { i , j } , fat ) ;
			cout << fat << " " << cnt_ << endl ;
			cnt[ fat ] = cnt_ ;
		}
	}
	sss
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
char t[ N + 1 ][ N + 1 ] ;
bool vis[ N ][ N ] ;
int id[ N ][ N ] ;
int cnt[ N*N ] ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 0 <= x && x < n ) ;
	bool b = ( 0 <= y && y < m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	vis[ x ][ y ] = true ;
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( vis[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] != '.' ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	REP( i , n ) {
		scanf( "%s" , t[ i ] ) ;
	}
	REP( i , n ) {
		REP( j , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int mark = i*N + j ;
			int cnt_ = dfs( i , j , mark ) ;
			cnt[ mark ] = cnt_ ;
		}
	}
	REP( i , n ) {
		REP( j , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	REP( i , n ) {
		printf( "%s\n" , t[ i ] ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + 1 ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		tot += cnt[ id[ nx ][ ny ] ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int bfs( pii st , int mark ) {
	int cnt = 1 ;
	id[ st.fi ][ st.se ] = mark ;
	queue<pii> q ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( id[ b.fi ][ b.se ] != -1 ) continue ;
			id[ b.fi ][ b.se ] = mark ;
			cnt ++ ;
			q.push( b ) ;
		}
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] != -1 ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			int cnt_ = bfs( { i , j } , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N + N + 1 ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

int dfs( int x , int y , int mark ) {
	id[ x ][ y ] = mark ;
	int cnt = 1 ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( t[ nx ][ ny ] == '*' ) continue ;
		if( id[ nx ][ ny ] ) continue ;
		cnt += dfs( nx , ny , mark ) ;
	}
	return cnt ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( id[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = i*N + j ;
			int cnt_ = dfs( i , j , fat ) ;
			cnt[ fat ] = cnt_ ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define ff(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
//#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define endl '\n'
#define SZ(a) int(a.size())
#define pb push_back
#define cln( x , v ) memset( x , v , sizeof( x ) )
#define pi acos(-1.0)
#define e2( x ) ( 1LL*( x )*( x ) )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>
#define nxtPerm next_permutation
#define L( n ) 2 * n
#define R( n ) 2 * n + 1
#define A 1 , 0 , n - 1

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const ld EPS = 1e-8 ;
const int INF = (int)( 1e8 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 1e3 ) ;
int days_month[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

char t[ N + 1 ][ N + 1 ] ;
bool vis[ N + 1 ][ N + 1 ] ;
int id[ N + 1 ][ N + 1 ] ;
int cnt[ N*N ] ;
int dir[ 5 ] = { 1 , 0 , -1 , 0 , 1 } ;
int n , m ;
pii a , b ;

inline bool val( int x , int y ) {
	bool a = ( 1 <= x && x <= n ) ;
	bool b = ( 1 <= y && y <= m ) ;
	return a && b ;
}

queue<pii> q ;

void bfs( pii st , int mark ) {
	int cnt_ = 0 ;
	vis[ st.fi ][ st.se ] = true ;
	q.push( st ) ;
	while( !q.empty() ) {
		a = q.front() ;
		q.pop() ;
		id[ a.fi ][ a.se ] = mark ;
		cnt_ ++ ;
		REP( d , 4 ) {
			b.fi = a.fi + dir[ d ] ;
			b.se = a.se + dir[ d + 1 ] ;
			if( !val( b.fi , b.se ) ) continue ;
			if( t[ b.fi ][ b.se ] == '*' ) continue ;
			if( vis[ b.fi ][ b.se ] ) continue ;
			vis[ b.fi ][ b.se ] = true ;
			q.push( b ) ;
		}
	}
	cnt[ mark ] = cnt_ ;
}

void update( int x , int y ) {
	int tot = 1 ;
	set<int> ids ;
	REP( d , 4 ) {
		int nx = x + dir[ d ] ;
		int ny = y + dir[ d + 1 ] ;
		if( !val( nx , ny ) ) continue ;
		if( id[ nx ][ ny ] == -1 ) continue ;
		int id_ = id[ nx ][ ny ] ;
		if( ids.count( id_ ) ) continue ;
		ids.insert( id_ ) ;
		tot += cnt[ id_ ] ;
	}
	t[ x ][ y ] = '0' + tot%10 ;
}

int main()
{
//	ios_base::sync_with_stdio(0);
	cin >> n >> m ;
	ff( i , 1 , n ) {
		scanf( "%s" , t[ i ] + 1 ) ;
	}
	cln( id , -1 ) ;
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( vis[ i ][ j ] ) continue ;
			if( t[ i ][ j ] == '*' ) continue ;
			int fat = ( i - 1 )*N + ( j - 1 ) ;
			bfs( { i , j } , fat ) ;
		}
	}
	ff( i , 1 , n ) {
		ff( j , 1 , m ) {
			if( t[ i ][ j ] == '*' ) {
				update( i , j ) ;
			}
		}
	}
	ff( i , 1 , n ) {
		printf( "%s\n" , t[ i ] + 1 ) ;
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 7, INF = INT_MAX;
char a[N][N];
int comp[N][N], sz[N * N];
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
map < pair <int, int >, bool > mp;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= n * m + 7; ++i) {
        sz[i] = 0;
    }
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            a[i][j] = '*';
        }
    }
    for (int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    sz[0] = 0;
    int num = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '.' && comp[i][j] == 0) {
                queue< pair <int, int> > q;
                q.push(make_pair(i, j));
                mp[make_pair(i, j)] = true;
                while (!q.empty()) {
                    int ii = q.front().first;
                    int ij = q.front().second;
                    comp[ii][ij] = num;
                    sz[num]++;
                    for (int z = 0; z < 4; ++z) {
                        if (a[ii + di[z]][ij + dj[z]] == '.' &&
                            comp[ii + di[z]][ij + dj[z]] == 0 &&
                            mp[make_pair(ii + di[z], ij + dj[z])] != true) {
                            q.push(make_pair(ii + di[z], ij + dj[z]));
                            mp[make_pair(ii + di[z], ij + dj[z])] = true;
                        }
                    }
                    q.pop();
                }
                num++;
            }
        }
    }
    for (int i = 1; i < num; ++i) {
        sz[i] %= 10;
    }
    for (int i = 1; i <= n; ++i) {
        cout << endl;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '*') {
                vector<int> v;
                int razm = 1;
                razm += sz[comp[i][j - 1]];
                v.push_back(comp[i][j - 1]);
                char flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i + 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i + 1][j]];
                    v.push_back(comp[i + 1][j]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i][j + 1]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i][j + 1]];
                    v.push_back(comp[i][j + 1]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i - 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i - 1][j]];
                    v.push_back(comp[i - 1][j]);
                }
                cout << razm % 10;
            }
            else {
                cout << a[i][j];
            }
        }
    }

    return 0;
}


#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;

const int N = 1e3 + 7, INF = INT_MAX;
char a[N][N];
int comp[N][N];
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
int sz[N * N];

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    int num = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '.' && comp[i][j] == 0) {
                queue< pair <int, int> > q;
                q.push(make_pair(i, j));
                while (!q.empty()) {
                    int ii = q.front().first;
                    int ij = q.front().second;
                    comp[ii][ij] = num;
                    sz[num]++;
                    for (int z = 0; z < 4; ++z) {
                        if (a[ii + di[z]][ij + dj[z]] == '.' &&
                            comp[ii + di[z]][ij + dj[z]] == 0) {
                            q.push(make_pair(ii + di[z], ij + dj[z]));
                        }
                    }
                    q.pop();
                }
                num++;
            }
        }
    }
    for (int i = 1; i < num; ++i) {
        sz[i] %= 10;
    }
    for (int i = 1; i <= n; ++i) {
        cout << endl;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '*') {
                vector<int> v;
                int razm = 1;
                razm += sz[comp[i][j - 1]];
                v.push_back(comp[i][j - 1]);
                char flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i + 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i + 1][j]];
                    v.push_back(comp[i + 1][j]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i][j + 1]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i][j + 1]];
                    v.push_back(comp[i][j + 1]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i - 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i - 1][j]];
                    v.push_back(comp[i - 1][j]);
                }
                cout << razm % 10;
            }
            else {
                cout << a[i][j];
            }
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 7, INF = INT_MAX;
char a[N][N];
int comp[N][N], sz[N * N];
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
map < pair <int, int >, bool > mp;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            a[i][j] = '*';
        }
    }
    for (int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    int num = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '.' && comp[i][j] == 0) {
                queue< pair <int, int> > q;
                q.push(make_pair(i, j));
                mp[make_pair(i, j)] = true;
                while (!q.empty()) {
                    int ii = q.front().first;
                    int ij = q.front().second;
                    comp[ii][ij] = num;
                    sz[num]++;
                    for (int z = 0; z < 4; ++z) {
                        if (a[ii + di[z]][ij + dj[z]] == '.' &&
                            comp[ii + di[z]][ij + dj[z]] == 0 &&
                            mp[make_pair(ii + di[z], ij + dj[z])] != true) {
                            q.push(make_pair(ii + di[z], ij + dj[z]));
                            mp[make_pair(ii + di[z], ij + dj[z])] = true;
                        }
                    }
                    q.pop();
                }
                num++;
            }
        }
    }
    for (int i = 1; i < num; ++i) {
        sz[i] %= 10;
    }
    for (int i = 1; i <= n; ++i) {
        cout << endl;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '*') {
                vector<int> v;
                int razm = 1;
                set<int> st;
                st.insert(comp[i + 1][j]);
                st.insert(comp[i - 1][j]);
                st.insert(comp[i][j + 1]);
                st.insert(comp[i][j - 1]);
                set<int> :: iterator it;
                for (it = st.begin(); it != st.end(); ++it) {
                    razm += sz[*it];
                }
                cout << razm % 10;
            }
            else {
                cout << a[i][j];
            }
        }
    }

    return 0;
}


#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <map>
using namespace std;

const int N = 1e3 + 7, INF = INT_MAX;
char a[N][N];
int comp[N][N];
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
map < pair <int, int >, bool > mp;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, *sz;
    cin >> n >> m;
    sz = new int[n * m + 7];
    for (int i = 0; i <= n * m + 7; ++i) {
        sz[i] = 0;
    }
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            a[i][j] = '*';
        }
    }
    for (int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    sz[0] = 0;
    int num = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '.' && comp[i][j] == 0) {
                queue< pair <int, int> > q;
                q.push(make_pair(i, j));
                mp[make_pair(i, j)] = true;
                while (!q.empty()) {
                    int ii = q.front().first;
                    int ij = q.front().second;
                    comp[ii][ij] = num;
                    sz[num]++;
                    for (int z = 0; z < 4; ++z) {
                        if (a[ii + di[z]][ij + dj[z]] == '.' &&
                            comp[ii + di[z]][ij + dj[z]] == 0 &&
                            mp[make_pair(ii + di[z], ij + dj[z])] != true) {
                            q.push(make_pair(ii + di[z], ij + dj[z]));
                            mp[make_pair(ii + di[z], ij + dj[z])] = true;
                        }
                    }
                    q.pop();
                }
                num++;
            }
        }
    }
    for (int i = 1; i < num; ++i) {
        sz[i] %= 10;
    }
    for (int i = 1; i <= n; ++i) {
        cout << endl;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '*') {
                vector<int> v;
                int razm = 1;
                razm += sz[comp[i][j - 1]];
                v.push_back(comp[i][j - 1]);
                char flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i + 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i + 1][j]];
                    v.push_back(comp[i + 1][j]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i][j + 1]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i][j + 1]];
                    v.push_back(comp[i][j + 1]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i - 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i - 1][j]];
                    v.push_back(comp[i - 1][j]);
                }
                cout << razm % 10;
            }
            else {
                cout << a[i][j];
            }
        }
    }
    delete [] sz;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 7, INF = INT_MAX;
char a[N][N];
int comp[N][N];
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
map < pair <int, int >, bool > mp;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m, *sz;
    cin >> n >> m;
    sz = new int[n * m + 7];
    for (int i = 0; i <= n * m + 7; ++i) {
        sz[i] = 0;
    }
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            a[i][j] = '*';
        }
    }
    for (int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    sz[0] = 0;
    int num = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '.' && comp[i][j] == 0) {
                queue< pair <int, int> > q;
                q.push(make_pair(i, j));
                mp[make_pair(i, j)] = true;
                while (!q.empty()) {
                    int ii = q.front().first;
                    int ij = q.front().second;
                    comp[ii][ij] = num;
                    sz[num]++;
                    for (int z = 0; z < 4; ++z) {
                        if (a[ii + di[z]][ij + dj[z]] == '.' &&
                            comp[ii + di[z]][ij + dj[z]] == 0 &&
                            mp[make_pair(ii + di[z], ij + dj[z])] != true) {
                            q.push(make_pair(ii + di[z], ij + dj[z]));
                            mp[make_pair(ii + di[z], ij + dj[z])] = true;
                        }
                    }
                    q.pop();
                }
                num++;
            }
        }
    }
    for (int i = 1; i < num; ++i) {
        sz[i] %= 10;
    }
    for (int i = 1; i <= n; ++i) {
        cout << endl;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '*') {
                vector<int> v;
                int razm = 1;
                razm += sz[comp[i][j - 1]];
                v.push_back(comp[i][j - 1]);
                char flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i + 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i + 1][j]];
                    v.push_back(comp[i + 1][j]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i][j + 1]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i][j + 1]];
                    v.push_back(comp[i][j + 1]);
                }
                flag = false;
                for (int q = 0; q < v.size(); ++q) {
                    if (v[q] == comp[i - 1][j]) {
                        flag = true;
                    }
                }
                if (!flag) {
                    razm += sz[comp[i - 1][j]];
                    v.push_back(comp[i - 1][j]);
                }
                cout << razm % 10;
            }
            else {
                cout << a[i][j];
            }
        }
    }
    delete [] sz;

    return 0;
}


// pahle hafta tha track pr ab to saans bhi nahi leta
#include<bits/stdc++.h>
using namespace std ;
const int N =1010 , M =1010 ;
#define pii pair<int,int>
#define fi  first
#define se  second
string a[1001] ;
int m , n ;
inline bool is(register int x,register int y){    if(x>=0 and x<n and y>=0 and y<m ) return 1 ; return 0 ;}
void dfs(int x,int y ){
    stack<pii>q ;
    bool vis[1001][1001] ;
    memset(vis,false,sizeof(vis) ) ;
    q.push({x,y}) ;
    vis[x][y]=1 ;
    int C = 1;
    while(q.size() ) {
        //stack<pii>r = q ; cout<<"Stack before " << r.top().fi<<" " << ", " << r.top().se<<" is =(& c= "<<C<<")\n" ; while(r.size() ){cout<<r.top().fi<<' ' <<r.top().se<<" \n" ; r.pop() ; } cout <<"\n" ;
        pii tm = q.top() ;
        q.pop() ;
        x= tm.fi , y= tm.se  ;
        if(is(x+1,y) ) if(!vis[x+1][y] ) if(a[x+1][y]!='*'){++C; vis[x+1][y]=1 ; q.push({x+1,y}) ;}
        if(is(x-1,y) ) if(!vis[x-1][y] ) if(a[x-1][y]!='*'){++C; vis[x-1][y]=1 ; q.push({x-1,y}) ;}
        if(is(x,y-1) ) if(!vis[x][y-1] ) if(a[x][y-1]!='*'){++C; vis[x][y-1]=1 ; q.push({x,y-1}) ;}
        if(is(x,y+1) ) if(!vis[x][y+1] ) if(a[x][y+1]!='*'){++C; vis[x][y+1]=1 ; q.push({x,y+1}) ;}
    } cout<< C%10 ;
}
int main() {
    scanf("%d%d",&n,&m) ;
    char f[1001] ;
    for(int i=0;i<n;++i ) {
        scanf("%s",f) ;
        a[i] = f ;
    }
    for(int i=0;i<n;++i ) {
        for(int j=0;j<m;++j ) {
            if(a[i][j]=='*') {
                a[i][j]='.' ;
                dfs(i,j) ;
                a[i][j]='*' ;
            } else cout<<'.';
        } cout<<endl ;
    }
}


// pahle hafta tha track pr ab to saans bhi nahi leta
#include<bits/stdc++.h>
using namespace std ;
const int N =1010 , M =1010 ;
#define le(x)   cout<<#x<<" " << x << endl
#define pii pair<int,int>
#define fi  first
#define se  second
char a[N][M] ;
int m , n ;
inline bool is(register int x,register int y){    if(x>=0 and x<n and y>=0 and y<m ) return 1 ; return 0 ;}
void dfs(int x,int y ){
    stack<pii>q ;
    map<pii,bool>vis ;
    q.push({x,y}) ;
    vis[{x,y}] = 1 ;
    int C = 1;
    while(q.size() ) {
        pii tm = q.top() ;
        q.pop() ;
        x= tm.fi , y= tm.se  ;
        vis[tm]=1 ;
        if(is(x+1,y) ) if(!vis[{x+1,y}] ) if(a[x+1][y]!='*'){++C; q.push({x+1,y}) ;}
        if(is(x-1,y) ) if(!vis[{x-1,y}] ) if(a[x-1][y]!='*'){++C; q.push({x-1,y}) ;}
        if(is(x,y-1) ) if(!vis[{x,y-1}] ) if(a[x][y-1]!='*'){++C; q.push({x,y-1}) ;}
        if(is(x,y+1) ) if(!vis[{x,y+1}] ) if(a[x][y+1]!='*'){++C; q.push({x,y+1}) ;}
    } cout<<C%10 ;
}
int main() {
    ios_base::sync_with_stdio(0) ; cin.tie(0) ;
    cin>> n>> m ;
    for(int i=0;i<n;++i )
        for(int j=0;j<m;++j )
            cin>>a[i][j] ;
    for(int i=0;i<n;++i ) {
        for(int j=0;j<m;++j ) {
            if(a[i][j]=='*') {
                a[i][j]='.' ;
                dfs(i,j) ;
                a[i][j]='*' ;
            } else cout<<'.';
        } cout<<endl ;
    }

    // for(int i=0;i<n;++i )        for(int j=0;j<m;++j )             if(a[i][j]=='.' ) cout<<"." ;                else cout<< dis[{i,j}]%10  ;
}


// pahle hafta tha track pr ab to saans bhi nahi leta
#include<bits/stdc++.h>
using namespace std ;
const int N =1010 , M =1010 ;
#define pii pair<int,int>
#define fi  first
#define se  second
string a[1001] ;
register int m , n ;
inline bool is(register int x,register int y){    if(x>=0 and x<n and y>=0 and y<m ) return 1 ; return 0 ;}
void dfs(int x,int y ){
    stack<pii>q ;
    bool vis[1001][1001] ;
    memset(vis,false,sizeof(vis) ) ;
    q.push({x,y}) ;
    vis[x][y]=1 ;
    int C = 1;
    while(q.size() ) {
        //stack<pii>r = q ; cout<<"Stack before " << r.top().fi<<" " << ", " << r.top().se<<" is =(& c= "<<C<<")\n" ; while(r.size() ){cout<<r.top().fi<<' ' <<r.top().se<<" \n" ; r.pop() ; } cout <<"\n" ;
        pii tm = q.top() ;
        q.pop() ;
        x= tm.fi , y= tm.se  ;
        if(is(x+1,y) ) if(!vis[x+1][y] ) if(a[x+1][y]!='*'){++C; vis[x+1][y]=1 ; q.push({x+1,y}) ;}
        if(is(x-1,y) ) if(!vis[x-1][y] ) if(a[x-1][y]!='*'){++C; vis[x-1][y]=1 ; q.push({x-1,y}) ;}
        if(is(x,y-1) ) if(!vis[x][y-1] ) if(a[x][y-1]!='*'){++C; vis[x][y-1]=1 ; q.push({x,y-1}) ;}
        if(is(x,y+1) ) if(!vis[x][y+1] ) if(a[x][y+1]!='*'){++C; vis[x][y+1]=1 ; q.push({x,y+1}) ;}
    } cout<< C%10 ;
}
int main() {
    scanf("%d%d",&n,&m) ;
    char f[1001] ;
    for(int i=0;i<n;++i ) {
        scanf("%s",f) ;
        a[i] = f ;
    }
    for(int i=0;i<n;++i ) {
        for(int j=0;j<m;++j ) {
            if(a[i][j]=='*') {
                a[i][j]='.' ;
                dfs(i,j) ;
                a[i][j]='*' ;
            } else cout<<'.';
        } cout<<endl ;
    }
}


// pahle hafta tha track pr ab to saans bhi nahi leta
#include<bits/stdc++.h>
using namespace std ;
const int N =1010 , M =1010 ;
#define pii pair<int,int>
#define fi  first
#define se  second
char a[N][M] ;
int m , n ;
inline bool is(register int x,register int y){    if(x>=0 and x<n and y>=0 and y<m ) return 1 ; return 0 ;}
void dfs(int x,int y ){
    stack<pii>q ;
    map<pii,bool>vis ;
    q.push({x,y}) ;
    vis[{x,y}] = 1 ;
    int C = 1;
    while(q.size() ) {
        //stack<pii>r = q ; cout<<"Stack before " << r.top().fi<<" " << ", " << r.top().se<<" is =(& c= "<<C<<")\n" ; while(r.size() ){cout<<r.top().fi<<' ' <<r.top().se<<" \n" ; r.pop() ; } cout <<"\n" ;
        pii tm = q.top() ;
        q.pop() ;
        x= tm.fi , y= tm.se  ;
        if(is(x+1,y) ) if(!vis[{x+1,y}] ) if(a[x+1][y]!='*'){++C; vis[{x+1,y}]=1 ; q.push({x+1,y}) ;}
        if(is(x-1,y) ) if(!vis[{x-1,y}] ) if(a[x-1][y]!='*'){++C; vis[{x-1,y}]=1 ; q.push({x-1,y}) ;}
        if(is(x,y-1) ) if(!vis[{x,y-1}] ) if(a[x][y-1]!='*'){++C; vis[{x,y-1}]=1 ; q.push({x,y-1}) ;}
        if(is(x,y+1) ) if(!vis[{x,y+1}] ) if(a[x][y+1]!='*'){++C; vis[{x,y+1}]=1 ; q.push({x,y+1}) ;}
    } cout<< C%10 ;
}
int main() {
    ios_base::sync_with_stdio(0) ; cin.tie(0) ;
    cin>> n>> m ;
    for(int i=0;i<n;++i )
        for(int j=0;j<m;++j )
            cin>>a[i][j] ;
    for(int i=0;i<n;++i ) {
        for(int j=0;j<m;++j ) {
            if(a[i][j]=='*') {
                a[i][j]='.' ;
                dfs(i,j) ;
                a[i][j]='*' ;
            } else cout<<'.';
        } cout<<endl ;
    }
}


#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std ;
typedef long long int ll ;
int dx[4]={1, 0 , -1, 0} ;
int dy[4]={0, 1, 0, -1 } ;
int main() {
    ios_base::sync_with_stdio(0) ; cin.tie(0) ;
    int n, m ;
    cin >> n >> m ;
    char ch[n][m] ;
    int dp[2][n][m] ;
    for(int i=0;i<n;++i )
        for(int j=0;j<m;++j ) {
            cin>> ch[i][j] ;
            dp[0][i][j] = dp[1][i][j] = 0 ;
        }
    int c = 0 ;
    for(int i=0;i<n;++i ) {
        for(int j=0 ;j< m ;j++ ) {
            if( ch[i][j]=='*' or dp[0][i][j] > 0 )
                continue ;
            c++ ;
            vector<pii> v ;
            queue<pii> q ;
            q.push({i,j} ) ;
            v.push_back({i,j} ) ;
            dp[0][i][j] = c ;
            while( !q.empty() ) {
                auto p = q.front() ;
                q.pop() ;
                for(int k=0;k<4;++k ) {

                    int x = p.first + dx[k] ;
                    int y = p.second + dy[k] ;
                    if( x<0 or x>n-1 or y<0 or y>m-1 or dp[0][x][y]>0 or ch[x][y]=='*' )
                        continue ;
                    dp[0][x][y] = c ;
                    q.push({x,y}) ;
                    v.push_back({x,y}) ;
                }
            }
            for(auto p: v )
                dp[1][p.first][p.second ] = v.size() ;
        }
    }
    for(int i=0;i<n;++i ){
        for(int j=0;j<m;++j ) {
            if(ch[i][j]== '.') {
                cout<<"." ;
                continue ;
            }
            set<int> s ;
            ll ans = 0 ;
            for(int k=0;k< 4 ; ++k ) {
                int x = i + dx[k] , y = j+ dy[k] ;
                if(x<0 or x>n-1 or y<0 or y>m-1 )
                    continue ;
                if( s.find( dp[0][x][y] ) == s.end() )
                    ans += dp[1][x][y] ;
                s.insert(dp[0][x][y] ) ;
            }
            cout << (ans+1)%10 ;
        }
        cout<< endl ;
    }

}


// pahle hafta tha track pr ab to saans bhi nahi leta
#include<bits/stdc++.h>
using namespace std ;
const int N =1010 , M =1010 ;
#define pii pair<int,int>
#define fi  first
#define se  second
string a[1001] ;
int m , n ;
inline bool is(register int x,register int y){    if(x>=0 and x<n and y>=0 and y<m ) return 1 ; return 0 ;}
void dfs(int x,int y ){
    stack<pii>q ;
    map<pii,bool>vis ;
    q.push({x,y}) ;
    vis[{x,y}] = 1 ;
    int C = 1;
    while(q.size() ) {
        //stack<pii>r = q ; cout<<"Stack before " << r.top().fi<<" " << ", " << r.top().se<<" is =(& c= "<<C<<")\n" ; while(r.size() ){cout<<r.top().fi<<' ' <<r.top().se<<" \n" ; r.pop() ; } cout <<"\n" ;
        pii tm = q.top() ;
        q.pop() ;
        x= tm.fi , y= tm.se  ;
        if(is(x+1,y) ) if(!vis[{x+1,y}] ) if(a[x+1][y]!='*'){++C; vis[{x+1,y}]=1 ; q.push({x+1,y}) ;}
        if(is(x-1,y) ) if(!vis[{x-1,y}] ) if(a[x-1][y]!='*'){++C; vis[{x-1,y}]=1 ; q.push({x-1,y}) ;}
        if(is(x,y-1) ) if(!vis[{x,y-1}] ) if(a[x][y-1]!='*'){++C; vis[{x,y-1}]=1 ; q.push({x,y-1}) ;}
        if(is(x,y+1) ) if(!vis[{x,y+1}] ) if(a[x][y+1]!='*'){++C; vis[{x,y+1}]=1 ; q.push({x,y+1}) ;}
    } cout<< C%10 ;
}
int main() {
    scanf("%d%d",&n,&m) ;
    char f[1001] ;
    for(int i=0;i<n;++i ) {
        scanf("%s",f) ;
        a[i] = f ;
    }
    for(int i=0;i<n;++i ) {
        for(int j=0;j<m;++j ) {
            if(a[i][j]=='*') {
                a[i][j]='.' ;
                dfs(i,j) ;
                a[i][j]='*' ;
            } else cout<<'.';
        } cout<<endl ;
    }
}