#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}
ll ctr=0;
ll which[1000005],wsize[1000005];
ll cmp=0,cursi=0;
void dfs(list<ll> g[],ll s,bool visited[],vector<ll> vec,bool ch)
{
    visited[s]=true;
    if(ch)
    vec.pb(s);
    if(ch)
    cursi++;
    if(ch)
    which[s]=cmp;
    ctr++;
    for(auto it:g[s])
    if(!visited[it])
    dfs(g,it,visited,vec,ch);
}
ll cmpsize[1000005];
int main()
{
   fastio;
   ll n,m;
   cin>>n>>m;
   char str[1005][1005];
   list<ll> g[1000001];
   for(ll i=0;i<n;i++)
   {
       cin>>str[i];
   }
   ll ele;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {

           ele=m*i+j+1;
           if(i-1>=0)
           {
               if(str[i-1][j]=='.')
               g[ele].pb(ele-m);
           }
           if(i+1<n)
           {
               if(str[i+1][j]=='.')
               g[ele].pb(ele+m);
           }
           if(j+1<m)
           {
               if(str[i][j+1]=='.')
               g[ele].pb(ele+1);
           }
           if(j-1>=0)
           {
               if(str[i][j-1]=='.')
               g[ele].pb(ele-1);
           }
       }
   }

   bool visited[1000005];
   memset(visited,false,sizeof(visited));
  for(ll i=0;i<=1000000;i++)
  which[i]=-1;
  vector<ll> vec;

   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {
           if(!visited[i*m+j+1] && str[i][j]=='.')
           {
               vec.clear();
               cmp++;
               cursi=0;
               //vector<ll> vec;
               dfs(g,i*m+j+1,visited,vec,true);
               for(auto it:vec)
               wsize[it]=cursi;
               cmpsize[cmp]=cursi;
           }
       }
   }
   //cout<<which[13]<<which[14]<<which[15]<<which[9]<<which[19];

   ll front,back,left,right;
   for(ll i=0;i<n;i++)
   {
       string ans;
       for(ll j=0;j<m;j++)
       {
           if(str[i][j]=='.')
           ans.pb('.');
           else
           {
              if(j==0 || j==m-1 || i==0 || i==n-1)
              {
              ctr=0;
              memset(visited,false,sizeof(visited));
              vec.clear();
              dfs(g,i*m+j+1,visited,vec,false);
              ctr=ctr%10;
              ans.pb(char(ctr+48));
              }
              else
              {
                    front=which[(i+1)*m+j+1];
                    back=which[(i-1)*m+j+1];
                    left=which[i*m+j];
                    right=which[i*m+j+2];
                  //  cout<<which[2];

                    ctr=0;
                    set<ll> s;
                    s.insert(front);
                    s.insert(back);
                    s.insert(right);
                    s.insert(left);
                    for(auto it:s)
                    {
                     if(it!=-1)
                     ctr+=cmpsize[it];
                    }
                    ctr++;
                    ctr=ctr%10;
                    ans.pb(char(ctr+48));
              }
           }
       }
       cout<<ans<<"\n";
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}
ll ctr=0;
ll which[2000005],wsize[2000005];
ll cmp=0,cursi=0;
void dfs(list<ll> g[],ll s,bool visited[],vector<ll> vec,bool ch)
{
    visited[s]=true;
    if(ch)
    vec.pb(s);
    if(ch)
    cursi++;
    if(ch)
    which[s]=cmp;
    ctr++;
    for(auto it:g[s])
    if(!visited[it])
    dfs(g,it,visited,vec,ch);
}
ll cmpsize[2000005];
int main()
{
   fastio;
   ll n,m;
   cin>>n>>m;
   char str[1005][1005];
   list<ll> g[2000001];
   for(ll i=0;i<n;i++)
   {
       cin>>str[i];
   }
   ll ele;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {

           ele=m*i+j+1;
           if(i-1>=0)
           {
               if(str[i-1][j]=='.')
               g[ele].pb(ele-m);
           }
           if(i+1<n)
           {
               if(str[i+1][j]=='.')
               g[ele].pb(ele+m);
           }
           if(j+1<m)
           {
               if(str[i][j+1]=='.')
               g[ele].pb(ele+1);
           }
           if(j-1>=0)
           {
               if(str[i][j-1]=='.')
               g[ele].pb(ele-1);
           }
       }
   }

   bool visited[2000005];
   memset(visited,false,sizeof(visited));
  for(ll i=0;i<=1000000;i++)
  which[i]=-1;
  vector<ll> vec;

   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {
           if(!visited[i*m+j+1] && str[i][j]=='.')
           {
               vec.clear();
               cmp++;
               cursi=0;
               //vector<ll> vec;
               dfs(g,i*m+j+1,visited,vec,true);
               for(auto it:vec)
               wsize[it]=cursi;
               cmpsize[cmp]=cursi;
           }
       }
   }
   //cout<<which[13]<<which[14]<<which[15]<<which[9]<<which[19];

   ll front,back,left,right;
   string ans;
   for(ll i=0;i<n;i++)
   {
       ans.clear();
       for(ll j=0;j<m;j++)
       {
           if(str[i][j]=='.')
           ans.pb('.');
           else
           {
              if(j==0 || j==m-1 || i==0 || i==n-1)
              {
              ctr=0;
             // memset(visited,false,sizeof(visited));
              vec.clear();
              set<ll> s;
              if(i+1<n)
              s.insert(which[(i+1)*m+j+1]);
              if(i>=1)
              s.insert(which[(i-1)*m+j+1]);
              if(j+1<m)
              s.insert(which[i*m+j+2]);
              if(j>=1)
              s.insert(which[i*m+j]);
              for(auto it:s)
                    {
                     if(it!=-1)
                     ctr+=cmpsize[it];
                    }
             // dfs(g,i*m+j+1,visited,vec,false);
              ctr++;
              ctr=ctr%10;
              ans.pb(char(ctr+48));
              }
              else
              {
                    front=which[(i+1)*m+j+1];
                    back=which[(i-1)*m+j+1];
                    left=which[i*m+j];
                    right=which[i*m+j+2];
                  //  cout<<which[2];

                    ctr=0;
                    set<ll> s;
                    s.insert(front);
                    s.insert(back);
                    s.insert(right);
                    s.insert(left);
                    for(auto it:s)
                    {
                     if(it!=-1)
                     ctr+=cmpsize[it];
                    }
                    ctr++;
                    ctr=ctr%10;
                    ans.pb(char(ctr+48));
              }
           }
       }
       cout<<ans<<"\n";
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}
ll ctr=0;
void dfs(list<ll> g[],ll s,bool visited[])
{
    visited[s]=true;
    ctr++;
    for(auto it:g[s])
    if(!visited[it])
    dfs(g,it,visited);
}
int main()
{
   fastio;
   ll n,m;
   cin>>n>>m;
   char str[1001][1001];
   list<ll> g[100001];
   for(ll i=0;i<n;i++)
   {
       cin>>str[i];
   }
   ll ele;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {

           ele=m*i+j+1;
           if(i-1>=0)
           {
               if(str[i-1][j]=='.')
               g[ele].pb(ele-m);
           }
           if(i+1<n)
           {
               if(str[i+1][j]=='.')
               g[ele].pb(ele+m);
           }
           if(j+1<m)
           {
               if(str[i][j+1]=='.')
               g[ele].pb(ele+1);
           }
           if(j-1>=0)
           {
               if(str[i][j-1]=='.')
               g[ele].pb(ele-1);
           }
       }
   }
   bool visited[1000005];
   for(ll i=0;i<n;i++)
   {
       string ans;
       for(ll j=0;j<m;j++)
       {
           if(str[i][j]=='.')
           ans.pb('.');
           else
           {
              ctr=0;
              memset(visited,false,sizeof(visited));
              dfs(g,i*m+j+1,visited);
              ctr=ctr%10;
              ans.pb(char(ctr+48));
           }
       }
       cout<<ans<<"\n";
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}
ll ctr=0;
void dfs(list<ll> g[],ll s,bool visited[])
{
    visited[s]=true;
    ctr++;
    for(auto it:g[s])
    if(!visited[it])
    dfs(g,it,visited);
}
int main()
{
   fastio;
   ll n,m;
   cin>>n>>m;
   char str[1001][1001];
   list<ll> g[100001];
   for(ll i=0;i<n;i++)
   {
       cin>>str[i];
   }
   ll ele;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {

           ele=m*i+j+1;
           if(i-1>=0)
           {
               if(str[i-1][j]=='.')
               g[ele].pb(ele-m);
           }
           if(i+1<n)
           {
               if(str[i+1][j]=='.')
               g[ele].pb(ele+m);
           }
           if(j+1<m)
           {
               if(str[i][j+1]=='.')
               g[ele].pb(ele+1);
           }
           if(j-1>=0)
           {
               if(str[i][j-1]=='.')
               g[ele].pb(ele-1);
           }
       }
   }
   bool visited[1000005];
   for(ll i=0;i<n;i++)
   {
       string ans;
       for(ll j=0;j<m;j++)
       {
           if(str[i][j]=='.')
           ans.pb('.');
           else
           {
              ctr=0;
              memset(visited,false,sizeof(visited));
              dfs(g,i*m+j+1,visited);
              ans.pb(char(ctr+48));
           }
       }
       cout<<ans<<"\n";
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}
ll ctr=0;
ll which[1000005],wsize[1000005];
ll cmp=0,cursi=0;
void dfs(list<ll> g[],ll s,bool visited[],vector<ll> vec,bool ch)
{
    visited[s]=true;
    if(ch)
    vec.pb(s);
    if(ch)
    cursi++;
    if(ch)
    which[s]=cmp;
    ctr++;
    for(auto it:g[s])
    if(!visited[it])
    dfs(g,it,visited,vec,ch);
}
ll cmpsize[1000001];
int main()
{
   fastio;
   ll n,m;
   cin>>n>>m;
   char str[1001][1001];
   list<ll> g[100001];
   for(ll i=0;i<n;i++)
   {
       cin>>str[i];
   }
   ll ele;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {

           ele=m*i+j+1;
           if(i-1>=0)
           {
               if(str[i-1][j]=='.')
               g[ele].pb(ele-m);
           }
           if(i+1<n)
           {
               if(str[i+1][j]=='.')
               g[ele].pb(ele+m);
           }
           if(j+1<m)
           {
               if(str[i][j+1]=='.')
               g[ele].pb(ele+1);
           }
           if(j-1>=0)
           {
               if(str[i][j-1]=='.')
               g[ele].pb(ele-1);
           }
       }
   }

   bool visited[1000005];
   memset(visited,false,sizeof(visited));
  for(ll i=0;i<=1000000;i++)
  which[i]=-1;
  vector<ll> vec;

   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {
           if(!visited[i*m+j+1] && str[i][j]=='.')
           {
               vec.clear();
               cmp++;
               cursi=0;
               //vector<ll> vec;
               dfs(g,i*m+j+1,visited,vec,true);
               for(auto it:vec)
               wsize[it]=cursi;
               cmpsize[cmp]=cursi;
           }
       }
   }
   //cout<<which[13]<<which[14]<<which[15]<<which[9]<<which[19];

   ll front,back,left,right;
   for(ll i=0;i<n;i++)
   {
       string ans;
       for(ll j=0;j<m;j++)
       {
           if(str[i][j]=='.')
           ans.pb('.');
           else
           {
              if(j==0 || j==m-1 || i==0 || i==n-1)
              {
              ctr=0;
              memset(visited,false,sizeof(visited));
              vec.clear();
              dfs(g,i*m+j+1,visited,vec,false);
              ctr=ctr%10;
              ans.pb(char(ctr+48));
              }
              else
              {
                    front=which[(i+1)*m+j+1];
                    back=which[(i-1)*m+j+1];
                    left=which[i*m+j];
                    right=which[i*m+j+2];
                  //  cout<<which[2];

                    ctr=0;
                    set<ll> s;
                    s.insert(front);
                    s.insert(back);
                    s.insert(right);
                    s.insert(left);
                    for(auto it:s)
                    {
                     if(it!=-1)
                     ctr+=cmpsize[it];
                    }
                    ctr++;
                    ctr=ctr%10;
                    ans.pb(char(ctr+48));
              }
           }
       }
       cout<<ans<<"\n";
   }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#define MrN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
using namespace std;

int n, m;
char M[1001][1001];
int A[1001][1001];
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

int DxDy(int r, int c, bool Vis[][1001], int Sum = 0) {

	//cout << r << " " << c << '\n';

	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.' && !Vis[X][Y]) {
			Vis[X][Y] = true;
			Sum += DxDy(X, Y, Vis) + 1;
		}
	}

	return Sum;
}
int main() {
	MrN;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> M[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			bool Vis[1001][1001] = {};
			if (M[i][j] == '*') {
				A[i][j] = (DxDy(i, j, Vis) + 1)%10;
			}

		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			if (M[i][j] == '*')
				cout << A[i][j];
			else
				cout << '.';

		cout << '\n';
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#define MrN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
using namespace std;

int n, m;
char M[1001][1001];
int dx[] = { 0, 0, 0, -1, 1 };
int dy[] = { 0, 1, -1, 0, 0 };

int DxDy(int r, int c, bool Vis[][1001], int Sum = 0) {

	//cout << r << " " << c << '\n';

	for (int k = 0; k < 5; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.' && !Vis[X][Y]) {
			Vis[X][Y] = true;
			Sum += DxDy(X, Y, Vis) + 1;
		}
	}

	return Sum;
}
int main() {
	MrN;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> M[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			bool Vis[1001][1001] = {};
			if (M[i][j] == '*') {
				int x = DxDy(i, j, Vis) + '0' + 1;
				M[i][j] = (x);
			}

		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cout << M[i][j];

		cout << '\n';
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#define MrN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
using namespace std;

int n, m;
char M[1001][1001];
int CntForCmp[1000001];
int Vis[1001][1001];
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int CompNum = 0;

int DFS(int r, int c, int ConnComp = 0) {
	//mark it as visited and give it a number to know
	//the count of this component
	Vis[r][c] = CompNum;

	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.' && Vis[X][Y] == 0) {
			ConnComp += DFS(X, Y) + 1;
		}
	}

	return ConnComp;
}

int DxDy(int r, int c, int Sum = 0) {

	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.') {
			//the Vis holds the Component Number
			//Each number has a number of components attached to it
			Sum += CntForCmp[Vis[X][Y]];
		}
	}

	return Sum;
}
int main() {
	MrN;
	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> M[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (Vis[i][j]==0 && M[i][j] == '.') {
				CompNum++;
				int ConnCnt = DFS(i, j) + 1;
				CntForCmp[CompNum] = ConnCnt;
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (M[i][j] == '*') {
				//check the count for the four directions then add one.
				int x = (DxDy(i, j) + 1) % 10 + '0';
				M[i][j] = (x);
			}

		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cout << M[i][j];

		cout << '\n';
	}

	return 0;
}


#include <iostream>
#include <string>
#define MrN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int n, m;
char M[1001][1001];
int A[1001][1001];
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

int DxDy(int r, int c, bool Vis[][1001], int Sum = 0) {

	//cout << r << " " << c << '\n';

	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.' && !Vis[X][Y]) {
			Vis[X][Y] = true;
			Sum += DxDy(X, Y, Vis) + 1;
		}
	}

	return Sum;
}
int main() {
	MrN;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> M[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			bool Vis[1001][1001] = {};
			if (M[i][j] == '*') {
				A[i][j] = DxDy(i, j, Vis) + 1;;
			}

		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			if (M[i][j] == '*')
				cout << A[i][j];
			else
				cout << '.';

		cout << '\n';
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <set>
#define MrN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
using namespace std;

int n, m;
char M[1001][1001];
int CntForCmp[1000001];
int Vis[1001][1001];
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int CompNum = 0;

int DFS(int r, int c, int ConnComp = 0) {
	//mark it as visited and give it a number to know
	//the count of this component
	Vis[r][c] = CompNum;

	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.' && Vis[X][Y] == 0) {
			ConnComp += DFS(X, Y) + 1;
		}
	}

	return ConnComp;
}

int DxDy(int r, int c, int Sum = 0) {

	set<int> Set;
	for (int k = 0; k < 4; ++k) {
		int X = dx[k] + r;
		int Y = dy[k] + c;

		if (X < 0 && Y < 0 && X >= n && Y >= m) continue;

		if (M[X][Y] == '.') {
			//the Vis holds the Component Number
			//Each number has a number of components attached to it
			Set.insert(Vis[X][Y]);
		}
	}
	for(auto s : Set)
		Sum += CntForCmp[s];

	return Sum;
}
int main() {
	MrN;
	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> M[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (Vis[i][j]==0 && M[i][j] == '.') {
				CompNum++;
				int ConnCnt = DFS(i, j) + 1;
				CntForCmp[CompNum] = ConnCnt;
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (M[i][j] == '*') {
				//check the count for the four directions then add one.
				int x = (DxDy(i, j) + 1) % 10 + '0';
				M[i][j] = (x);
			}

		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cout << M[i][j];

		cout << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll c[1020][1020], sz[1000020], dx[4] = {0 , 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int n, m;
bool mark[1020][1020];
char jadval[1020][1020];

bool in(int x, int y)
{
	if(x >= 0 && x < n && y >= 0 && y < m)
		return true;
	return false;
}

void dfs_number(int x, int y, int comp)
{
	mark[x][y] = true;
	c[x][y] = comp;
	for(int i = 0; i < 4; i++)
	{
		int vx = x + dx[i];
		int vy = y + dy[i];
		if(in(vx , vy) && !mark[vx][vy] && jadval[vx][vy] == '.')
			dfs_number(vx , vy, comp);
	}
}

int main()
{
	vector<int> v;
	int cnt = 0, ans = 1;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> jadval[i][j];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			if(!mark[i][j] && jadval[i][j] == '.')
			{
				cnt++;
				dfs_number(i , j , cnt);
			}
	}
	for(int i = 0; i < n; i++)
		for(int j = 0 ; j < m; j++)
			if(jadval[i][j] == '.')
				sz[c[i][j]]++;
	for(int i = 0; i < n; i++)
	{
		if(i != 0)
			cout << endl;
		for(int j = 0; j < m; j++)
		{
			if(jadval[i][j] == '.')
				cout << '.';
			else
			{
				ans = 1;
				v.clear();
				for(int k = 0; k < 4; k++)
				{
					int vx = i + dx[k];
					int vy = j + dy[k];
					if(in(vx , vy) && jadval[vx][vy] != '*')
						v.push_back(c[vx][vy]);
				}

				if(v.size() > 0)
				{
					sort(v.begin() , v.end());
					ans += sz[v[0]];
				}
				for(int w = 1; w < v.size(); w++)
					if(v[w] != v[w - 1])
						ans += sz[v[w]];
				cout << ans % 10;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int c[1020][1020], sz[1020], dx[4] = {0 , 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int n, m;
bool mark[1020][1020];
char jadval[1020][1020];

bool in(int x, int y)
{
	if(x >= 0 && x < n && y >= 0 && y < m)
		return true;
	return false;
}

void dfs_number(int x, int y, int comp)
{
	mark[x][y] = true;
	c[x][y] = comp;
	for(int i = 0; i < 4; i++)
	{
		int vx = x + dx[i];
		int vy = y + dy[i];
		if(in(vx , vy) && !mark[vx][vy] && jadval[vx][vy] == '.')
			dfs_number(vx , vy, comp);
	}
}

int main()
{
	vector<int> v;
	int cnt = 0, ans = 1;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> jadval[i][j];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			if(!mark[i][j] && jadval[i][j] == '.')
			{
				cnt++;
				dfs_number(i , j , cnt);
			}
	}
	for(int i = 0; i < n; i++)
		for(int j = 0 ; j < m; j++)
			if(jadval[i][j] == '.')
				sz[c[i][j]]++;
	for(int i = 0; i < n; i++)
	{
		if(i != 0)
			cout << endl;
		for(int j = 0; j < m; j++)
		{
			if(jadval[i][j] == '.')
				cout << '.';
			else
			{
				ans = 1;
				v.clear();
				for(int k = 0; k < 4; k++)
				{
					int vx = i + dx[k];
					int vy = j + dy[k];
					if(in(vx , vy) && jadval[vx][vy] != '*')
						v.push_back(c[vx][vy]);
				}
				sort(v.begin() , v.end());
				ans += sz[v[0]];
				for(int w = 1; w < v.size(); w++)
					if(v[w] != v[w - 1])
						ans += sz[v[w]];
				cout << ans % 10;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int c[1020][1020], sz[1020], dx[4] = {0 , 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int n, m;
bool mark[1020][1020];
char jadval[1020][1020];

bool in(int x, int y)
{
	if(x >= 0 && x < n && y >= 0 && y < m)
		return true;
	return false;
}

void dfs_number(int x, int y, int comp)
{
	mark[x][y] = true;
	c[x][y] = comp;
	for(int i = 0; i < 4; i++)
	{
		int vx = x + dx[i];
		int vy = y + dy[i];
		if(in(vx , vy) && !mark[vx][vy] && jadval[vx][vy] == '.')
			dfs_number(vx , vy, comp);
	}
}

int main()
{
	vector<int> v;
	int cnt = 0, ans = 1;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> jadval[i][j];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			if(!mark[i][j] && jadval[i][j] == '.')
			{
				cnt++;
				dfs_number(i , j , cnt);
			}
	}
	for(int i = 0; i < n; i++)
		for(int j = 0 ; j < m; j++)
			if(jadval[i][j] == '.')
				sz[c[i][j]]++;
	for(int i = 0; i < n; i++)
	{
		if(i != 0)
			cout << endl;
		for(int j = 0; j < m; j++)
		{
			if(jadval[i][j] == '.')
				cout << '.';
			else
			{
				ans = 1;
				v.clear();
				for(int k = 0; k < 4; k++)
				{
					int vx = i + dx[k];
					int vy = j + dy[k];
					if(in(vx , vy) && jadval[vx][vy] != '*')
						v.push_back(c[vx][vy]);
				}

				if(v.size() > 0)
				{
					sort(v.begin() , v.end());
					ans += sz[v[0]];
				}
				for(int w = 1; w < v.size(); w++)
					if(v[w] != v[w - 1])
						ans += sz[v[w]];
				cout << ans % 10;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll c[1020][1020], sz[1020], dx[4] = {0 , 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int n, m;
bool mark[1020][1020];
char jadval[1020][1020];

bool in(int x, int y)
{
	if(x >= 0 && x < n && y >= 0 && y < m)
		return true;
	return false;
}

void dfs_number(int x, int y, int comp)
{
	mark[x][y] = true;
	c[x][y] = comp;
	for(int i = 0; i < 4; i++)
	{
		int vx = x + dx[i];
		int vy = y + dy[i];
		if(in(vx , vy) && !mark[vx][vy] && jadval[vx][vy] == '.')
			dfs_number(vx , vy, comp);
	}
}

int main()
{
	vector<int> v;
	int cnt = 0, ans = 1;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> jadval[i][j];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			if(!mark[i][j] && jadval[i][j] == '.')
			{
				cnt++;
				dfs_number(i , j , cnt);
			}
	}
	for(int i = 0; i < n; i++)
		for(int j = 0 ; j < m; j++)
			if(jadval[i][j] == '.')
				sz[c[i][j]]++;
	for(int i = 0; i < n; i++)
	{
		if(i != 0)
			cout << endl;
		for(int j = 0; j < m; j++)
		{
			if(jadval[i][j] == '.')
				cout << '.';
			else
			{
				ans = 1;
				v.clear();
				for(int k = 0; k < 4; k++)
				{
					int vx = i + dx[k];
					int vy = j + dy[k];
					if(in(vx , vy) && jadval[vx][vy] != '*')
						v.push_back(c[vx][vy]);
				}

				if(v.size() > 0)
				{
					sort(v.begin() , v.end());
					ans += sz[v[0]];
				}
				for(int w = 1; w < v.size(); w++)
					if(v[w] != v[w - 1])
						ans += sz[v[w]];
				cout << ans % 10;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
	int n,m;
bool ok(int u,int v){
	if(u<1 or v<1 or u>n or v>m) return 1;
	return 0;
}
const int NN=1020;
char a[NN][NN];
int fl[NN][NN],cnt,nn[NN*NN];
void dfs(int u,int v){
	fl[u][v]=cnt;
	nn[cnt]++;
	for(int i=0;i<4;i++){
		int uu=u+dx[i];
		int vv=v+dy[i];
		if(ok(uu,vv) or fl[uu][vv] or a[uu][vv]=='*') continue;
		dfs(uu,vv);
	}
}
set <int> st;
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='*') continue;
			if(fl[i][j]) continue;
			cnt++;
			dfs(i,j);
//			cerr<<nn[cnt]<<endl;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='.'){
				printf(".");
				continue;
			}
			for(int k=0;k<4;k++){
				int u=i+dx[k];
				int v=j+dy[k];
				if(ok(u,v) or a[u][v]=='*') continue;
				st.insert(fl[u][v]);
			}
			int ans=0;
			for(int u:st) ans+=nn[u];
			ans++;
			ans%=10;
			st.clear();
			printf("%d",ans);
		}
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define NN 1010
using namespace std;

char str[NN][NN];
int vst[NN][NN];
typedef pair<int, int> pii;
queue<pii> que;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
int mem[10];
bool out(int u, int v){
	if(u < 1 || u > n || v < 1 || v > m) return 1;
	return 0;
}
int cnt[NN];
void bfs(int ct){
	cnt[ct] = 1;
	while(!que.empty()){
		pii p = que.front();
		que.pop();
		for(int i = 0; i < 4; i++){
			int x = p.x + dx[i];
			int y = p.y + dy[i];
			if(out(x, y)) continue;
			if(str[x][y] == '*') continue;
			if(vst[x][y]) continue;
			que.push(pii(x, y));
			vst[x][y] = ct;
			cnt[ct]++;
		}
	}

}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)	cin>>str[i] + 1;
	int ct = 1;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '*') continue;
			if(vst[i][j]) continue;
			ct++;
			vst[i][j] = ct;
			que.push(pii(i, j));
			bfs(ct);
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '.') cout<<str[i][j];
			else {
				int t = 0;
				mem[1] = vst[i + 1][j];
				mem[2] = vst[i][j - 1];
				mem[3] = vst[i][j + 1];
				mem[4] = vst[i - 1][j];
				sort(mem + 1, mem + 5);
				for(int i = 1; i <= 4; i++){
					if(mem[i] != mem[i - 1]) t += cnt[mem[i]];
				}

				cout<<t + 1;
			}
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1010
char board[NN][NN];
int flag[NN][NN];
int cnt[NN*NN];
int sa[10];
int n;
int m;
int id;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, -1, 1};

int out(int u, int v) {
	return (u<1 or u>n or v<1 or v>m);
}

void dfs(int x, int y) {
	flag[x][y]=id;
	cnt[id]++;
	for (int d=0; d<4; d++) {
		int xx=x+dx[d], yy=y+dy[d];
		if (board[xx][yy]=='*') continue;
		if (out(xx, yy) or flag[xx][yy]) continue;
		dfs(xx, yy);
	}
}

int main () {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out","w",stdout);
#endif
    //ios_base::sync_with_stdio(0); cin.tie(0);
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++) scanf(" %s", board[i]+1);
	id=0;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			if (board[i][j]=='*') continue;
			if (flag[i][j]) continue;
			id++;
			dfs(i, j);
		}
//
//	for (int i=1; i<=n; i++) {
//		for (int j=1; j<=m; j++) cout<<cnt[flag[i][j]]<<" ";
//		cout<<endl;
//	}
//	return 0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (board[i][j]=='.') {putchar(board[i][j]); continue;}
			int nn=0;
			if (flag[i][j-1]) sa[nn++]=flag[i][j-1];
			if (flag[i][j+1]) sa[nn++]=flag[i][j+1];
			if (flag[i+1][j]) sa[nn++]=flag[i+1][j];
			if (flag[i-1][j]) sa[nn++]=flag[i-1][j];
			nn=unique(sa, sa+nn)-sa;
			int ans=0;
			for (int i=0; i<nn; i++) ans+=cnt[sa[i]];
			ans++;
			putchar(ans%10+'0');
		}
		puts("");
	}
}


#include<bits/stdc++.h>

using namespace std;

int dx[]={0, 0, -1, 1}, n;
int dy[]={-1, 1, 0, 0}, m;

#define NN 1010
#define pb push_back
#define x first
#define y second

using pii=pair<int, int>;

char s[NN][NN];
int vst[NN][NN], val[NN][NN], runs;
vector<pii> vec;

inline bool out(int u, int v) {
	return u<1 || v<1 || u>n || v>m;
}

void dfs(int u, int v) {
	vec.pb({u, v}), vst[u][v]=runs;
	for(int i=4; i--; ) {
		int x=u+dx[i], y=v+dy[i];
		if(out(x, y) || s[x][y]=='*' || vst[x][y]) continue;
		dfs(x, y);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	scanf("%d %d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) if(s[i][j]=='.' && !vst[i][j]) {
			runs++, vec.clear();
			dfs(i, j);
			int sz=vec.size();
			for(pii p: vec) val[p.x][p.y]=sz;
		}
	}

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j]=='.') putchar('.');
			else {
				vec.clear();
				for(int k=4; k--; ) {
					int x=i+dx[k], y=j+dy[k];
					if(!out(x, y)) vec.pb({vst[x][y], val[x][y]});
				}
				sort(vec.begin(), vec.end());
				vec.resize(unique(vec.begin(), vec.end())-vec.begin());

				int ans=1;
				for(pii p: vec) ans+=p.y;
				putchar('0'+ans%10);
			}
		}
		puts("");
	}
}


#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int n,m,node;
int out(int u,int v){
	if(u<0 or v<0 or u>=n or v>=m) return 1;
	return 0;
}
int cnt[1000100],vst[1010][1010];
char s[1010][1010];
set <int> st;
queue<int> q;
void bfs(int u,int v){
	cnt[node]++;
	q.push(u),q.push(v);
	vst[u][v]=node;
	while(!q.empty()){
		int x=q.front();q.pop();
		int y=q.front();q.pop();
		for(int i=0;i<4;i++){
			int xx=x+dx[i];
			int yy=y+dy[i];
			if(out(xx,yy) or s[xx][yy]=='*')continue;
			if(vst[xx][yy]) continue;
			q.push(xx);q.push(yy);
			vst[xx][yy]=node;
			cnt[node]++;
		}
	}
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) cin>>s[i];
	node=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='*' or vst[i][j])continue;
			node++;
			bfs(i,j);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='.') {cout<<'.';continue;}
			int t=0;
			for(int k=0;k<4;k++){
				int a=i+dx[k];
				int b=j+dy[k];
				if(out(a,b) or s[a][b]=='*') continue;
				st.insert(vst[a][b]);
			}
			for(int u:st) t+=cnt[u];
			t++;
			printf("%d",t%10);
			st.clear();
		}
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1010
char s[NN][NN];
int id[NN][NN];

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int vst[NN][NN];
int n,m;
int runs;

bool out(int x,int y){
	return x<1||x>n||y<1||y>m;
}

int cnt;
void dfs(int u,int v){
	cnt++;
	vst[u][v]=runs;
	for(int i=0;i<4;i++){
		int uu=u+dx[i];
		int vv=v+dy[i];
		if(out(uu,vv)||vst[uu][vv]==runs||s[uu][vv]=='*') continue;
		dfs(uu,vv);
	}
}

int f[NN*NN];
int flag[NN*NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int E=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(vst[i][j]||s[i][j]=='*') continue;
			runs++;
			cnt=0;
			dfs(i,j);
			f[runs]=cnt;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='*'){
				int ans=0;
				E++;
				for(int k=0;k<4;k++){
					int u=i+dx[k];
					int v=j+dy[k];
					if(out(u,v)||s[u][v]=='*') continue;
					int id=vst[u][v];
					if(flag[id]!=E) ans+=f[id];
					flag[id]=E;
				}
				ans++;
				ans%=10;
				printf("%d",ans);
			}
			else{
				putchar('.');
			}
		}
		puts("");
	}
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define NN 1010
using namespace std;

char str[NN][NN];
int vst[NN][NN];
int cnt[NN * NN];

typedef pair<int, int> pii;
queue<pii> que;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
int mem[10];
bool out(int u, int v){
	if(u < 1 || u > n || v < 1 || v > m) return 1;
	return 0;
}

void bfs(int ct){
	cnt[ct] = 1;
	while(!que.empty()){
		pii p = que.front();
		que.pop();
		for(int i = 0; i < 4; i++){
			int x = p.x + dx[i];
			int y = p.y + dy[i];
			if(out(x, y)) continue;
			if(str[x][y] == '*') continue;
			if(vst[x][y] == ct) continue;
			que.push(pii(x, y));
			vst[x][y] = ct;
			cnt[ct]++;
		}
	}

}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)	cin>>str[i] + 1;
	int ct = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '*') continue;
			if(vst[i][j]) continue;
			ct++;
			vst[i][j] = ct;
			que.push(pii(i, j));
			bfs(ct);
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '.') cout<<str[i][j];
			else {
				int t = 0;
				mem[1] = vst[i + 1][j];
				mem[2] = vst[i][j - 1];
				mem[3] = vst[i][j + 1];
				mem[4] = vst[i - 1][j];
				sort(mem + 1, mem + 5);
				for(int i = 1; i <= 4; i++){
					if(mem[i] != mem[i - 1]) t += cnt[mem[i]];
				}

				cout<<(t + 1) % 10;
			}
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1010
char board[NN][NN];
int flag[NN][NN];
int cnt[NN*NN];
int sa[10];
int n;
int m;
int id;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, -1, 1};

int out(int u, int v) {
	return (u<1 or u>n or v<1 or v>m);
}

void dfs(int x, int y) {
	flag[x][y]=id;
	cnt[id]++;
	for (int d=0; d<4; d++) {
		int xx=x+dx[d], yy=y+dy[d];
		if (board[xx][yy]=='*') continue;
		if (out(xx, yy) or flag[xx][yy]) continue;
		dfs(xx, yy);
	}
}

int main () {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out","w",stdout);
#endif
    //ios_base::sync_with_stdio(0); cin.tie(0);
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++) scanf(" %s", board[i]+1);
	id=0;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			if (board[i][j]=='*') continue;
			if (flag[i][j]) continue;
			id++;
			dfs(i, j);
		}
//
//	for (int i=1; i<=n; i++) {
//		for (int j=1; j<=m; j++) cout<<cnt[flag[i][j]]<<" ";
//		cout<<endl;
//	}
//	return 0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (board[i][j]=='.') {putchar(board[i][j]); continue;}
			int nn=0;
			if (flag[i][j-1]) sa[nn++]=flag[i][j-1];
			if (flag[i][j+1]) sa[nn++]=flag[i][j+1];
			if (flag[i-1][j]) sa[nn++]=flag[i-1][j];
			if (flag[i+1][j]) sa[nn++]=flag[i+1][j];
			sort(sa, sa+nn);
			nn=unique(sa, sa+nn) - sa;
			int ans=0;
			for (int i=0; i<nn; i++) ans+=cnt[sa[i]];
			ans++;
			putchar(ans%10+'0');
		}
		puts("");
	}
}


#include<bits/stdc++.h>

#define NN 1010

using namespace std;

typedef long long INT;
typedef pair<int,int>pii;

char s[NN][NN];
pii p[]={{0,1},{0,-1},{1,0},{-1,0},};

int vst[NN][NN],ans[NN][NN],cnt,ct[NN*NN],flag[NN*NN];

int runs,n,m;

void dfs(int u,int v){
	runs++;
	vst[u][v]=cnt;
	for(int i=0;i<4;i++){
		int t=p[i].first;
		int ss=p[i].second;
		if(u+t<1 or u+t>n)continue;
		if(v+ss<0 or v+ss>=m)continue;
		if(vst[u+t][v+ss])continue;
		if(s[u+t][v+ss]=='*')continue;
		dfs(u+t,v+ss);
	}
	ct[cnt]=runs%10;
	return ;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif

	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]);
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='.'){
				if(vst[i][j])continue;
				cnt++;
				runs=0;
				dfs(i,j);
			}
		}
	}

	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='*'){
				ans[i][j]=1;
				vector<int>res;
				for(int k=0;k<4;k++){
					int t=p[k].first,u=i;
					int ss=p[k].second,v=j;
					if(u+t<1 or u+t>n)continue;
					if(v+ss<0 or v+ss>=m)continue;
					if(s[u+t][v+ss]=='*')continue;
					int r=vst[u+t][v+ss];
					if(flag[r]==0)ans[i][j]+=ct[r];
					flag[r]=1;
					res.push_back(r);
				}
				for(int v:res)flag[v]=0;
				ans[i][j]%=10;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='.')printf("%c",s[i][j]);
			else printf("%c",ans[i][j]+'0');
		}
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define NN 1010
using namespace std;

char str[NN][NN];
int vst[NN][NN];

typedef pair<int, int> pii;
queue<pii> que;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
int mem[10];
bool out(int u, int v){
	if(u < 1 || u > n || v < 1 || v > m) return 1;
	return 0;
}
int cnt[NN * NN];
void bfs(int ct){
	cnt[ct] = 1;
	while(!que.empty()){
		pii p = que.front();
		que.pop();
		for(int i = 0; i < 4; i++){
			int x = p.x + dx[i];
			int y = p.y + dy[i];
			if(out(x, y)) continue;
			if(str[x][y] == '*') continue;
			if(vst[x][y] == ct) continue;
			que.push(pii(x, y));
			vst[x][y] = ct;
			cnt[ct]++;
		}
	}

}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)	cin>>str[i] + 1;
	int ct = 1;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '*') continue;
			if(vst[i][j]) continue;
			ct++;
			vst[i][j] = ct;
			que.push(pii(i, j));
			bfs(ct);
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(str[i][j] == '.') cout<<str[i][j];
			else {
				int t = 0;
				mem[1] = vst[i + 1][j];
				mem[2] = vst[i][j - 1];
				mem[3] = vst[i][j + 1];
				mem[4] = vst[i - 1][j];
				sort(mem + 1, mem + 5);
				for(int i = 1; i <= 4; i++){
					if(mem[i] != mem[i - 1]) t += cnt[mem[i]];
				}

				cout<<t + 1;
			}
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

void dfs(int,int,int,int,int&);
string s[1001];
int color[1001][1001];
int visit[1001][1001];
int paint;

int main()
{
  FIO
 int n,m,i,j,k,t,c;
 paint=0;

 unordered_map<int,int> map;
 unordered_set<int> p;
 map[0]=0;

     cin>>n>>m;

    for(i=0;i<1001;i++)
     fill_n(color[i],1001,0);

     for(i=0;i<n;i++)
       cin>>s[i];

        for(i=0;i<n;i++)
        {
          for(j=0;j<m;j++)
           {
             c=0;
              if(s[i][j]=='.' && color[i][j]==0)
              {    paint++;
                  dfs(i,j,n,m,c);
                  map[paint]=c;
              }

           }
        }

        for(i=0;i<n;i++)
        {
          string s2="";
          for(j=0;j<m;j++)
          {
            c=0;
              if(s[i][j]=='*')
              {
                int rt[]={-1,0,0,1};
                int ct[]={0,-1,1,0};

                //cout<<"Hello"<<endl;

                for(int k=0;k<4;k++)
                {
                   int r=i+rt[k];
                   int c=j+ct[k];

                   if(r>=0 && r<n && c>=0 && c<m)
                     p.insert(color[r][c]);

                }

                for(int val:p)
                 c+=map[val];

                 c++;
                 c=c%10;

                 p.clear();

                 string s1;
                 stringstream ss;
                 ss<<c;
                 ss>>s1;

                 s2=s2+s1;
              }

              else
              s2=s2+s[i][j];
            }
            cout<<s2<<endl;
          }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
   color[row][col]=paint;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

void dfs(int,int,int,int,int&);
string s[1001];
int color[1001][1001];
int visit[1001][1001];
int paint;

int main()
{
  FIO
 int n,m,i,j,k,t,c;
 paint=0;

 unordered_map<int,int> map;
 map[0]=0;

     cin>>n>>m;

    for(i=0;i<1001;i++)
     fill_n(color[i],1001,0);

     for(i=0;i<n;i++)
       cin>>s[i];

        for(i=0;i<n;i++)
        {
          for(j=0;j<m;j++)
           {
             c=0;
              if(s[i][j]=='.' && color[i][j]==0)
              {    paint++;
                  dfs(i,j,n,m,c);
                  map[paint]=c;
              }

           }
        }

        //cout<<"Hello"<<endl;

        for(i=0;i<n;i++)
        {
          for(j=0;j<m;j++)
           {  cout<<color[i][j];
           }
           cout<<endl;
        }

        unordered_set<int> p;

        for(i=0;i<n;i++)
        {
          string s2="";
          for(j=0;j<m;j++)
          {
            c=0;
              if(s[i][j]=='*')
              {
                int rt[]={-1,0,0,1};
                int ct[]={0,-1,1,0};

                //cout<<"Hello"<<endl;

                for(int k=0;k<4;k++)
                {
                   int r=i+rt[k];
                   int c=j+ct[k];

                   if(r>=0 && r<n && c>=0 && c<m)
                     p.insert(color[r][c]);

                }

                for(int val:p)
                 c+=map[val];

                 c++;

                 p.clear();

                 string s1;
                 stringstream ss;
                 ss<<c;
                 ss>>s1;

                 s2=s2+s1;
              }

              else
              s2=s2+s[i][j];
            }
            cout<<s2<<endl;
          }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
   color[row][col]=paint;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&);
char s[1001][1001];
int visit[1001][1001];

int main()
{
  FIO

  int n,m,i,j,k,t,c;

    cin>>n>>m;
    //int visit[n+1][m+1];

    for(i=0;i<n;i++)
       for(j=0;j<m;j++)
        cin>>s[i][j];

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                s[i][j]='.';c=0;
                dfs(i,j,n,m,c);

                for(k=0;k<=n;k++)
                 for(t=0;t<=m;t++)
                 visit[k][t]=0;

                s[i][j]='*';

                cout<<(c%10);
              }

              else
                cout<<s[i][j];
           }
           cout<<endl;
        }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

void dfs(int,int,int,int,int&);
string s[1001];
int color[1001][1001];
int visit[1001][1001];
int paint;

int main()
{
  FIO
 int n,m,i,j,k,t,c;
 paint=0;

 unordered_map<int,int> map;
 map[0]=0;

     cin>>n>>m;

    for(i=0;i<1001;i++)
     fill_n(color[i],1001,0);

     for(i=0;i<n;i++)
       cin>>s[i];

        for(i=0;i<n;i++)
        {
          for(j=0;j<m;j++)
           {
             c=0;
              if(s[i][j]=='.' && color[i][j]==0)
              {    paint++;
                  dfs(i,j,n,m,c);
                  map[paint]=c;
              }

           }
        }

        unordered_set<int> p;

        for(i=0;i<n;i++)
        {
          string s2="";
          for(j=0;j<m;j++)
          {
            c=0;
              if(s[i][j]=='*')
              {
                int rt[]={-1,0,0,1};
                int ct[]={0,-1,1,0};

                //cout<<"Hello"<<endl;

                for(int k=0;k<4;k++)
                {
                   int r=i+rt[k];
                   int c=j+ct[k];

                   if(r>=0 && r<n && c>=0 && c<m)
                     p.insert(color[r][c]);

                }

                for(int val:p)
                 c+=map[val];

                 c++;
                 c=c%10;

                 p.clear();

                 string s1;
                 stringstream ss;
                 ss<<c;
                 ss>>s1;

                 s2=s2+s1;
              }

              else
              s2=s2+s[i][j];
            }
            cout<<s2<<endl;
          }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
   color[row][col]=paint;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&);
char s[1001][1001];
int visit[1001][1001];

int main()
{
  FIO

  int n,m,i,j,k,t,c;

    cin>>n>>m;
    //int visit[n+1][m+1];

    for(i=0;i<n;i++)
       for(j=0;j<m;j++)
        cin>>s[i][j];

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                s[i][j]='.';c=0;
                dfs(i,j,n,m,c);

                for(k=0;k<n;k++)
                 for(t=0;t<m;t++)
                 visit[k][t]=0;

                s[i][j]='*';

                cout<<c;
              }

              else
                cout<<s[i][j];
           }
           cout<<endl;
        }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

void dfs(int,int,int,int,int&);
string s[1001];
int color[1001][1001];
int visit[1001][1001];
int paint;

int main()
{
  FIO
 int n,m,i,j,k,t,c;
 paint=0;

 unordered_map<int,int> map;
 map[0]=0;

     cin>>n>>m;

    for(i=0;i<1001;i++)
     fill_n(color[i],1001,0);

     for(i=0;i<n;i++)
       cin>>s[i];

        for(i=0;i<n;i++)
        {
          for(j=0;j<m;j++)
           {
             c=0;
              if(s[i][j]=='.' && color[i][j]==0)
              {    paint++;
                  dfs(i,j,n,m,c);
                  map[paint]=c;
              }

           }
        }

        unordered_set<int> p;

        for(i=0;i<n;i++)
        {
          string s2="";
          for(j=0;j<m;j++)
          {
            c=0;
              if(s[i][j]=='*')
              {
                int rt[]={-1,0,0,1};
                int ct[]={0,-1,1,0};

                //cout<<"Hello"<<endl;

                for(int k=0;k<4;k++)
                {
                   int r=i+rt[k];
                   int c=j+ct[k];

                   if(r>=0 && r<n && c>=0 && c<m)
                     p.insert(color[r][c]);

                }

                for(int val:p)
                 c+=map[val];

                 c++;

                 p.clear();

                 string s1;
                 stringstream ss;
                 ss<<c;
                 ss>>s1;

                 s2=s2+s1;
              }

              else
              s2=s2+s[i][j];
            }
            cout<<s2<<endl;
          }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
   color[row][col]=paint;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&,int visit[][1001]);
string s[1001];

int main()
{
  FIO
 int n,m,i,j,k,t,c;

    cin>>n>>m;
    //

    for(i=0;i<n;i++)
      cin>>s[i];

        for(i=0;i<n;i++)
        {
          string row="";

           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                int visit[n][1001]={0};
                s[i][j]='.';
                c=0;
                dfs(i,j,n,m,c,visit);

                s[i][j]='*';
                c=c%10;

                string s1;
                stringstream ss;
                ss<<c;
                ss>>s1;
                row=row+s1;

              }

              else
                row=row+s[i][j];
           }
           cout<<row<<"\n";

        }

}

void dfs(int row,int col,int R,int C,int &count,int visit[][1001])
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count,visit);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&,int visit[][1001]);
string s[1001];

int main()
{
  FIO
 int n,m,i,j,k,t,c;

    cin>>n>>m;
    //

    for(i=0;i<n;i++)
      cin>>s[i];

        for(i=0;i<n;i++)
        {string row="";
           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                int visit[n][1001]={0};
                s[i][j]='.';c=0;
                dfs(i,j,n,m,c,visit);

                s[i][j]='*';
                c=c%10;

                string s1=to_string(c);
                row=row+s1;

              }

              else
                row=row+s[i][j];
           }
           cout<<row<<endl;

        }

}

void dfs(int row,int col,int R,int C,int &count,int visit[][1001])
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count,visit);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&);
char s[1001][1001];
char ch[1001][1001];
int visit[1001][1001];

int main()
{
  FIO

  int n,m,i,j,k,t,c;

    cin>>n>>m;
    //int visit[n+1][m+1];

    for(i=0;i<n;i++)
       for(j=0;j<m;j++)
        cin>>s[i][j];

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                s[i][j]='.';c=0;
                dfs(i,j,n,m,c);

                for(k=0;k<=n;k++)
                 for(t=0;t<=m;t++)
                 visit[k][t]=0;

                s[i][j]='*';

                ch[i][j]=(char)(c%10);
              }

              else
                ch[i][j]=s[i][j];
           }

        }

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
             if(ch[i][j]!='.')
              cout<<(int)ch[i][j];

              else
               cout<<ch[i][j];
           }
           cout<<endl;
        }
}

void dfs(int row,int col,int R,int C,int &count)
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count);
   }
}


#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
void dfs(int,int,int,int,int&,int visit[][1001]);
char s[1001][1001];
char ch[1001][1001];
//int visit[1001][1001];

int main()
{
  FIO

  int n,m,i,j,k,t,c;

    cin>>n>>m;
    //

    for(i=0;i<n;i++)
       for(j=0;j<m;j++)
        cin>>s[i][j];

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
              if(s[i][j]=='*')
              {
                int visit[n][1001]={0};
                s[i][j]='.';c=0;
                dfs(i,j,n,m,c,visit);

              /*  for(k=0;k<=n;k++)
                 for(t=0;t<=m;t++)
                 visit[k][t]=0;*/
                s[i][j]='*';

                ch[i][j]=(char)(c%10);
              }

              else
                ch[i][j]=s[i][j];
           }

        }

        for(i=0;i<n;i++)
        {
           for(j=0;j<m;j++)
           {
             if(ch[i][j]!='.')
              cout<<(int)ch[i][j];

              else
               cout<<ch[i][j];
           }
           cout<<endl;
        }
}

void dfs(int row,int col,int R,int C,int &count,int visit[][1001])
{
   visit[row][col]=1;
   count++;
//   cout<<count<<"  ("<<row<<","<<col<<")"<<endl;
   static int rt[]={-1,0,0,1};
   static int ct[]={0,-1,1,0};

   for(int i=0;i<4;i++)
   {
      int r=row+rt[i];
      int c=col+ct[i];
      if(r>=0 && r<R && c>=0 && c<C && s[r][c]=='.' && !visit[r][c])
        dfs(r,c,R,C,count,visit);
   }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define max2(a,b) ((a)>(b)?(a):(b))
#define min2(a,b) ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
#define cerr if(0)cerr

int n,m; char c[1005][1005];
map< pii, pii > dsu;
map< pii , int> cnt;
bool vis[1005][1005];

pii find_parent( pii p )
{
	if(dsu[p]!=p)
		return dsu[p]=find_parent(dsu[p]);
	    return p;
}
void merge( pii p1, pii p2 )
{
	pii pp1=find_parent(p1);
	pii pp2=find_parent(p2);

	if(pp1==pp2) return;

	if(cnt[pp1]<cnt[pp2])
		swap(pp1,pp2);

	cnt[pp1]+=cnt[pp2];
	dsu[pp2]=pp1;
}

void dfs(int x,int y,int px,int py)
{
	if(x<1 || x>n ||y<1 || y>m) return;
	if(c[x][y]=='*') return;
	if(vis[x][y]==1) return;
	vis[x][y]=1;

     merge({px,py},{x,y});

   if(!(x-1==px && y==py))
     dfs(x-1,y,x,y);
   if(!(x+1==px && y==py))
     dfs(x+1,y,x,y);
   if(!(x==px && y-1==py))
     dfs(x,y-1,x,y);
   if(!(x==px && y+1==py))
     dfs(x,y+1,x,y);
}

void solve()
{
   cin>>n>>m;
   rep(i,1,n)
    rep(j,1,m)
    {
    	cin>>c[i][j];
    	dsu[{i,j}]={i,j};
    	cnt[{i,j}]=1;
    }

    rep(i,1,n)
      rep(j,1,m)
        if(!vis[i][j])
        	  dfs(i,j,i,j);

       bug("hello");

char fin[n+1][m+1];

    rep(i,1,n)
      rep(j,1,m)
        if(c[i][j]=='*')
        {
           ll ans=0;
            spii s;

           if(c[i-1][j]!='*')
                 s.ins(find_parent({i-1,j}));

           if(c[i+1][j]!='*')
                 s.ins(find_parent({i+1,j}));

           if(c[i][j-1]!='*')
                 s.ins(find_parent({i,j-1}));

           if(c[i][j+1]!='*')
                 s.ins(find_parent({i,j+1}));

             for(auto it:s)
             	ans+=cnt[it];
             ++ans;

            fin[i][j]=ans%10 + '0';
        }
        else fin[i][j]=c[i][j];

    rep(i,1,n)
     {
     rep(j,1,m)
     cout<<fin[i][j];
     cout<<'\n';
     }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define max2(a,b) ((a)>(b)?(a):(b))
#define min2(a,b) ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
#define cerr if(0)cerr

int n,m; char c[1005][1005];
map< pii, pii > dsu;
map< pii , int> cnt;
bool vis[1005][1005];

void init(pii p)
{
	dsu[p]=p;
	cnt[p]=1;
}
pii find_parent( pii p )
{
	if(dsu[p]!=p)
		return dsu[p]=find_parent(dsu[p]);
	    return p;
}
void merge( pii p1, pii p2 )
{
	pii pp1=find_parent(p1);
	pii pp2=find_parent(p2);

	if(pp1==pp2) return;

	if(cnt[pp1]<cnt[pp2])
		swap(pp1,pp2);

	cnt[pp1]+=cnt[pp2];
	dsu[pp2]=pp1;
}

void dfs(int x,int y,int px,int py)
{
	if(x<1 || x>n ||y<1 || y>m) return;
	if(c[x][y]=='*') return;
	if(vis[x][y]==1) return;
	vis[x][y]=1;

     merge({px,py},{x,y});

     dfs(x-1,y,x,y);
     dfs(x+1,y,x,y);
     dfs(x,y-1,x,y);
     dfs(x,y+1,x,y);
}

ll compute(int x,int y,vpii & v)
{
   if(x<1 || x>n || y<1 || y>m) return 0;
   if(c[x][y]=='*') return 0;

   pii p=find_parent({x,y});

   rep(k,0,sz(v)-1)
     if(v[k]==p) return 0;
     v.pb(p);

   return cnt[p];
}
void solve()
{
   cin>>n>>m;
   rep(i,1,n)
    rep(j,1,m) cin>>c[i][j];

   rep(i,1,n)
     rep(j,1,m)
       	 init({i,j});

    rep(i,1,n)
      rep(j,1,m)
        if(!vis[i][j])
        	  dfs(i,j,i,j);

       bug("hello");

char fin[n+1][m+1];

    rep(i,1,n)
      rep(j,1,m)
        if(c[i][j]=='*')
        {
           ll ans=0;
           vpii v;
           ans+=compute(i-1,j,v);
           ans+=compute(i+1,j,v);
           ans+=compute(i,j-1,v);
           ans+=compute(i,j+1,v);
           ++ans;

            fin[i][j]=ans%10 + '0';
        }
        else fin[i][j]=c[i][j];

    rep(i,1,n)
     {
     rep(j,1,m)
     cout<<fin[i][j];
     cout<<'\n';
     }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define max2(a,b) ((a)>(b)?(a):(b))
#define min2(a,b) ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
#define cerr if(0)cerr

int n,m; char c[1005][1005];
map< pii, pii > dsu;
map< pii , int> cnt;
bool vis[1005][1005];

pii find_parent( pii p )
{
	if(dsu[p]!=p)
		return dsu[p]=find_parent(dsu[p]);
	    return p;
}
void merge( pii p1, pii p2 )
{
	pii pp1=find_parent(p1);
	pii pp2=find_parent(p2);

	if(pp1==pp2) return;

	if(cnt[pp1]<cnt[pp2])
		swap(pp1,pp2);

	cnt[pp1]+=cnt[pp2];
	dsu[pp2]=pp1;
}

int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
void solve()
{
   cin>>n>>m;
   rep(i,1,n)
    rep(j,1,m)
    {
    	cin>>c[i][j];
    	dsu[{i,j}]={i,j};
    	cnt[{i,j}]=1;
    }

rep(i,1,n)
 rep(j,1,m)
  if(!vis[i][j] && c[i][j]=='.')
  {
  queue< pii > q;
  q.push({i,j});

  while(sz(q))
  {
  	pii p=q.front();
  	q.pop();
  	int x=p.fi,y=p.se;
  	vis[x][y]=1;

      rep(k,0,3)
       {
       	 int u=x+dx[k],v=y+dy[k];
       	 if(u<1 || u>n || v<1 || v>m)
       	 {}
       	 else if(vis[u][v]==0 && c[u][v]=='.')
       	 {
       	 	q.push({u,v});
       	 	vis[u][v]=1;
       	 	merge({x,y},{u,v});
       	 }
       }
  }
}
    // rep(i,1,n)
    //   rep(j,1,m)
    //      {
    //      	pii p={i,j};
    //      	bug(dsu[p].fi); bug(dsu[p].se);
    //      	bug(i); bug(j);
    //      	bug(cnt[p]);
    //      	cout<<'\n';
    //      }

char fin[n+1][m+1];

    rep(i,1,n)
      rep(j,1,m)
        if(c[i][j]=='*')
        {
           ll ans=0;
            spii s;

           if(c[i-1][j]!='*')
                 s.ins(find_parent({i-1,j}));

           if(c[i+1][j]!='*')
                 s.ins(find_parent({i+1,j}));

           if(c[i][j-1]!='*')
                 s.ins(find_parent({i,j-1}));

           if(c[i][j+1]!='*')
                 s.ins(find_parent({i,j+1}));

             for(auto it:s)
             	ans+=cnt[it];
             ++ans;

            fin[i][j]=ans%10 + '0';
        }
        else fin[i][j]=c[i][j];

    rep(i,1,n)
     {
     rep(j,1,m)
     cout<<fin[i][j];
     cout<<'\n';
     }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define max2(a,b) ((a)>(b)?(a):(b))
#define min2(a,b) ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
#define cerr if(0)cerr

int n,m; char c[1005][1005];
map< pii, pii > dsu;
map< pii , int> cnt;
bool vis[1005][1005];

pii find_parent( pii p )
{
	if(dsu[p]!=p)
		return dsu[p]=find_parent(dsu[p]);
	    return p;
}
void merge( pii p1, pii p2 )
{
	pii pp1=find_parent(p1);
	pii pp2=find_parent(p2);

	if(pp1==pp2) return;

	if(cnt[pp1]<cnt[pp2])
		swap(pp1,pp2);

	cnt[pp1]+=cnt[pp2];
	dsu[pp2]=pp1;
}

void dfs(int x,int y,int px,int py)
{
	if(x<1 || x>n ||y<1 || y>m) return;
	if(c[x][y]=='*') return;
	if(vis[x][y]==1) return;
	vis[x][y]=1;

     merge({px,py},{x,y});

   if(!(x-1==px && y==py))
     dfs(x-1,y,x,y);
   if(!(x+1==px && y==py))
     dfs(x+1,y,x,y);
   if(!(x==px && y-1==py))
     dfs(x,y-1,x,y);
   if(!(x==px && y+1==py))
     dfs(x,y+1,x,y);
}

ll compute(int x,int y,vpii & v)
{
   if(x<1 || x>n || y<1 || y>m) return 0;
   if(c[x][y]=='*') return 0;

   pii p=find_parent({x,y});

   rep(k,0,sz(v)-1)
     if(v[k]==p) return 0;
     v.pb(p);

   return cnt[p];
}
void solve()
{
   cin>>n>>m;
   rep(i,1,n)
    rep(j,1,m)
    {
    	cin>>c[i][j];
    	dsu[{i,j}]={i,j};
    	cnt[{i,j}]=1;
    }

    rep(i,1,n)
      rep(j,1,m)
        if(!vis[i][j])
        	  dfs(i,j,i,j);

       bug("hello");

char fin[n+1][m+1];

    rep(i,1,n)
      rep(j,1,m)
        if(c[i][j]=='*')
        {
           ll ans=0;
           vpii v;
           ans+=compute(i-1,j,v);
           ans+=compute(i+1,j,v);
           ans+=compute(i,j-1,v);
           ans+=compute(i,j+1,v);
           ++ans;

            fin[i][j]=ans%10 + '0';
        }
        else fin[i][j]=c[i][j];

    rep(i,1,n)
     {
     rep(j,1,m)
     cout<<fin[i][j];
     cout<<'\n';
     }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define max2(a,b) ((a)>(b)?(a):(b))
#define min2(a,b) ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
#define cerr if(0)cerr

int n,m; char c[1005][1005];
pii dsu[1005][1005];
int cnt[1005][1005];
bool vis[1005][1005];

void init(pii p)
{
	dsu[p.fi][p.se]=p;
	cnt[p.fi][p.se]=1;
}
pii find_parent( pii p )
{
	if(dsu[p.fi][p.se]!=p)
		return dsu[p.fi][p.se]=find_parent(dsu[p.fi][p.se]);
	    return p;
}
void merge( pii p1, pii p2 )
{
	pii pp1=find_parent(p1);
	pii pp2=find_parent(p2);

	if(pp1==pp2) return;

	if(cnt[pp1.fi][pp1.se]<cnt[pp2.fi][pp2.se])
		swap(pp1,pp2);

	cnt[pp1.fi][pp1.se]+=cnt[pp2.fi][pp2.se];
	dsu[pp2.fi][pp2.se]=pp1;
}

void dfs(int x,int y,int px,int py)
{
	if(x<1 || x>n ||y<1 || y>m) return;
	if(c[x][y]=='*') return;
	if(vis[x][y]==1) return;
	vis[x][y]=1;

     merge({px,py},{x,y});

     dfs(x-1,y,x,y);
     dfs(x+1,y,x,y);
     dfs(x,y-1,x,y);
     dfs(x,y+1,x,y);
}

ll compute(int x,int y,vpii & v)
{
   if(x<1 || x>n || y<1 || y>m) return 0;
   if(c[x][y]=='*') return 0;

   pii p=find_parent({x,y});

   rep(k,0,sz(v)-1)
     if(v[k]==p) return 0;
     v.pb(p);

   return cnt[p.fi][p.se];
}
void solve()
{
   cin>>n>>m;
   rep(i,1,n)
    rep(j,1,m) cin>>c[i][j];

   rep(i,1,n)
     rep(j,1,m)
       	 init({i,j});

    rep(i,1,n)
      rep(j,1,m)
        if(!vis[i][j])
        	  dfs(i,j,i,j);

       bug("hello");

char fin[n+1][m+1];

    rep(i,1,n)
      rep(j,1,m)
        if(c[i][j]=='*')
        {
           ll ans=0;
           vpii v;
           ans+=compute(i-1,j,v);
           ans+=compute(i+1,j,v);
           ans+=compute(i,j-1,v);
           ans+=compute(i,j+1,v);
           ++ans;

            fin[i][j]=ans%10 + '0';
        }
        else fin[i][j]=c[i][j];

    rep(i,1,n)
     {
     rep(j,1,m)
     cout<<fin[i][j];
     cout<<'\n';
     }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <memory>
#include <functional>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double pi = acos((long double)-1.0);
const long double eps = 1e-8;

int Counter = 0;
int n, m;
char A[maxn][maxn];
bool mark[maxn][maxn];
pair <int, int> C[maxn][maxn];
int ans[maxn][maxn], answ[maxn][maxn];
int color[maxn][maxn];
int Color = 1;

vector < pair <int, int> > D = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

void bfs(int x, int y) {
	mark[x][y] = true;
	queue < pair <int, int> > Q;
	Q.push(mp(x, y));
	C[x][y] = mp(x, y);
	auto root = mp(x, y);
	++Counter;
	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for (auto to : D) {
			int r = to.first, c = to.second;
			if (x + r <= n && x + r > 0 && y + c <= m && y + c > 0) {
				if (!mark[x + r][y + c] && A[x + r][y + c] == '.') {
					mark[x + r][y + c] = true;
					C[x + r][y + c] = root;
					Q.push({ x + r, y + c });
					++Counter;
				}
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			Counter = 0;
			if (A[i][j] == '.' && !mark[i][j]) {
				bfs(i, j);
				ans[i][j] = Counter;
				color[i][j] = Color++;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			answ[i][j] = 1;
			set <int> S;
			for (auto to : D) {
				int r = to.first, c = to.second;
				if (!S.count(color[C[i + r][j + c].first][C[i + r][j + c].second])) {
					answ[i][j] += ans[C[i + r][j + c].first][C[i + r][j + c].second];
					S.insert(color[C[i + r][j + c].first][C[i + r][j + c].second]);
				}
			}
			answ[i][j] %= 10;
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (A[i][j] == '.') {
				cout << '.';
				continue;
			}
			cout << answ[i][j];
		}
		cout << endl;
	}
}

int main() {
	//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define freopen
#ifdef freopen
#ifndef _MSC_VER
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <memory>
#include <functional>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double pi = acos((long double)-1.0);
const long double eps = 1e-8;

int Counter = 0;
int n, m;
char A[maxn][maxn];
bool mark[maxn][maxn];
pair <int, int> C[maxn][maxn];
int ans[maxn][maxn], answ[maxn][maxn];
int color[maxn][maxn];
int Color = 1;

vector < pair <int, int> > D = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

void bfs(int x, int y) {
	mark[x][y] = true;
	queue < pair <int, int> > Q;
	Q.push(mp(x, y));
	C[x][y] = mp(x, y);
	auto root = mp(x, y);
	++Counter;
	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for (auto to : D) {
			int r = to.first, c = to.second;
			if (x + r <= n && x + r > 0 && y + c <= m && y + c > 0) {
				if (!mark[x + r][y + c] && A[x + r][y + c] == '.') {
					mark[x + r][y + c] = true;
					C[x + r][y + c] = root;
					Q.push({ x + r, y + c });
					++Counter;
				}
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			Counter = 0;
			if (A[i][j] == '.' && !mark[i][j]) {
				bfs(i, j);
				ans[i][j] = Counter;
				color[i][j] = Color++;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			answ[i][j] = 1;
			set <int> S;
			for (auto to : D) {
				int r = to.first, c = to.second;
				if (!S.count(color[C[i + r][j + c].first][C[i + r][j + c].second])) {
					answ[i][j] += ans[C[i + r][j + c].first][C[i + r][j + c].second];
					S.insert(color[C[i + r][j + c].first][C[i + r][j + c].second]);
				}
			}
			answ[i][j] %= 10;
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (A[i][j] == '.') {
				cout << '.';
				continue;
			}
			cout << answ[i][j];
		}
		cout << endl;
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define freopen
#ifdef freopen
#ifndef _MSC_VER
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <memory>
#include <functional>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double pi = acos((long double)-1.0);
const long double eps = 1e-8;

int Counter = 0;
int n, m;
char A[maxn][maxn];
bool mark[maxn][maxn];

vector < pair <int, int> > D = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

void bfs(int x, int y) {
	mark[x][y] = true;
	queue < pair <int, int> > Q;
	Q.push(mp(x, y));
	++Counter;
	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for (auto to : D) {
			int r = to.first, c = to.second;
			if (x + r <= n && x + r > 0 && y + c <= m && y + c > 0) {
				if (!mark[x + r][y + c] && A[x + r][y + c] == '.') {
					mark[x + r][y + c] = true;
					Q.push({ x + r, y + c });
					++Counter;
				}
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (A[i][j] == '.') {
				cout << '.';
				continue;
			}
			Counter = 0;
			A[i][j] = '.';
			bfs(i, j);
			cout << Counter;
			A[i][j] = '*';
			memset(mark, 0, sizeof mark);
		}
		cout << endl;
	}
}

int main() {
	//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define freopen
#ifdef freopen
#ifndef _MSC_VER
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <memory>
#include <functional>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double pi = acos((long double)-1.0);
const long double eps = 1e-8;

int Counter = 0;
int n, m;
char A[maxn][maxn];
bool mark[maxn][maxn];

vector < pair <int, int> > D = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

void bfs(int x, int y) {
	mark[x][y] = true;
	queue < pair <int, int> > Q;
	Q.push(mp(x, y));
	++Counter;
	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for (auto to : D) {
			int r = to.first, c = to.second;
			if (x + r <= n && x + r > 0 && y + c <= m && y + c > 0) {
				if (!mark[x + r][y + c] && A[x + r][y + c] == '.') {
					mark[x + r][y + c] = true;
					Q.push({ x + r, y + c });
					++Counter;
				}
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (A[i][j] == '.') {
				cout << '.';
				continue;
			}
			Counter = 0;
			A[i][j] = '.';
			bfs(i, j);
			cout << Counter % 10;
			A[i][j] = '*';
			memset(mark, 0, sizeof mark);
		}
		cout << endl;
	}
}

int main() {
	//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define freopen
#ifdef freopen
#ifndef _MSC_VER
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <memory>
#include <functional>
#include <sstream>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <tuple>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double pi = acos((long double)-1.0);
const long double eps = 1e-8;

int Counter = 0;
int n, m;
char A[maxn][maxn];
bool mark[maxn][maxn];
pair <int, int> C[maxn][maxn];
int ans[maxn][maxn], answ[maxn][maxn];

vector < pair <int, int> > D = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };

void bfs(int x, int y) {
	mark[x][y] = true;
	queue < pair <int, int> > Q;
	Q.push(mp(x, y));
	C[x][y] = mp(x, y);
	auto root = mp(x, y);
	++Counter;
	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for (auto to : D) {
			int r = to.first, c = to.second;
			if (x + r <= n && x + r > 0 && y + c <= m && y + c > 0) {
				if (!mark[x + r][y + c] && A[x + r][y + c] == '.') {
					mark[x + r][y + c] = true;
					C[x + r][y + c] = root;
					Q.push({ x + r, y + c });
					++Counter;
				}
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			Counter = 0;
			if (A[i][j] == '.' && !mark[i][j]) {
				bfs(i, j);
				ans[i][j] = Counter;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			answ[i][j] = 1 +
				ans[C[i + 1][j].first][C[i + 1][j].second] +
				ans[C[i - 1][j].first][C[i - 1][j].second] +
				ans[C[i][j + 1].first][C[i][j + 1].second] +
				ans[C[i][j - 1].first][C[i][j - 1].second];
			answ[i][j] %= 10;
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (A[i][j] == '.') {
				cout << '.';
				continue;
			}
			cout << answ[i][j];
		}
		cout << endl;
	}
}

int main() {
	//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define freopen
#ifdef freopen
#ifndef _MSC_VER
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);

const int maxn = 1e3 + 20;
int n , m;
string ar[maxn];
bool mark[maxn][maxn];
int ans[maxn][maxn], dx[] = {-1, 1, 0 , 0}, dy[] = {0, 0, -1, 1},  kr[maxn][maxn], koft = 1;

bool check(int i, int j, int k){
	if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m)
		return 1;
	return 0;
}

int dfs(int i, int j){
	mark[i][j] = 1;
	int ans = 1;
	for(int k = 0; k < 4; k ++){
		if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && !mark[i + dx[k]][j + dy[k]])
			ans += dfs(i + dx[k], j + dy[k]);
	}
	return ans;
}

int main(){
	IoFast;
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
		cin >> ar[i];
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < m; j ++){
			if (ar[i][j] == '.'){
				bool p = 0;
				for(int k  = 0; k < 4; k++)
					if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && ans[i + dx[k]][j + dy[k]] != 0)
						ans[i][j] = ans[i + dx[k]][j + dy[k]], p = 1, kr[i][j] = kr[i + dx[k]][j + dy[k]];
				if (!p){
					ans[i][j] = dfs(i, j);
					kr[i][j] = koft;
					koft ++ ;
				}
			}
		}
	}
	for(int i = 0; i < n ; i ++){
		for(int j = 0; j < m ; j ++){
			if (ar[i][j] == '.')
				cout << '.';
			else{
				set<int> kk;
				int koftt;
				int p = 0;

				for(int k  = 0; k < 4; k++)
					if (check(i, j, k)){
						koftt = (int)kk.size();
						kk.insert(kr[i + dx[k]][j + dy[k]]);
						if ((int)kk.size() > koftt)
							p += ans[i + dx[k]][j + dy[k]];
					}
				cout << p + 1 ;
			}
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>

using namespace std;
#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);

const int maxn = 1e3 + 20;
int n , m;
string ar[maxn];
bool mark[maxn][maxn];
int ans[maxn][maxn], dx[] = {-1, 1, 0 , 0}, dy[] = {0, 0, -1, 1},  kr[maxn][maxn], koft = 1;

bool check(int i, int j, int k){
	if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m)
		return 1;
	return 0;
}

int dfs(int i, int j){
	mark[i][j] = 1;
	int ans = 1;
	for(int k = 0; k < 4; k ++){
		if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && !mark[i + dx[k]][j + dy[k]])
			ans += dfs(i + dx[k], j + dy[k]);
	}
	return ans;
}

int main(){
	IoFast;
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
		cin >> ar[i];
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < m; j ++){
			if (ar[i][j] == '.'){
				bool p = 0;
				for(int k  = 0; k < 4; k++)
					if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && ans[i + dx[k]][j + dy[k]] != 0)
						ans[i][j] = ans[i + dx[k]][j + dy[k]], p = 1, kr[i][j] = kr[i + dx[k]][j + dy[k]];
				if (!p){
					ans[i][j] = dfs(i, j);
					kr[i][j] = koft;
					koft ++ ;
				}
			}
		}
	}
	for(int i = 0; i < n ; i ++){
		for(int j = 0; j < m ; j ++){
			if (ar[i][j] == '.')
				cout << '.';
			else{
				set<int> kk;
				int koftt;
				int p = 0;

				for(int k  = 0; k < 4; k++)
					if (check(i, j, k)){
						koftt = (int)kk.size();
						kk.insert(kr[i + dx[k]][j + dy[k]]);
						if ((int)kk.size() > koftt)
							p += ans[i + dx[k]][j + dy[k]];
					}
				cout << (p + 1) % 10;
			}
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>

using namespace std;
#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);

const int maxn = 1e3 + 20;
int n , m;
string ar[maxn];
bool mark[maxn][maxn];
int ans[maxn][maxn], dx[] = {-1, 1, 0 , 0}, dy[] = {0, 0, -1, 1},  kr[maxn][maxn], koft = 1;

int dfs(int i, int j){
	mark[i][j] = 1;
	int ans = 1;
	for(int k = 0; k < 4; k ++){
		if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m && ar[i + dx[k]][j + dy[k]] == '.' && !mark[i + dx[k]][j + dy[k]])
			ans += dfs(i + dx[i], j + dy[i]);
	}
	return ans;
}

int main(){
	IoFast;
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
		cin >> ar[i];
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < m; j ++){
			if (ar[i][j] == '.'){
				bool p = 0;
				for(int k  = 0; k < 4; k++)
					if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m && ar[i + dx[k]][j + dy[k]] == '.' && ans[i + dx[k]][j + dy[k]] != 0)
						ans[i][j] = ans[i + dx[k]][j + dy[k]], p = 1, kr[i][j] = kr[i + dx[k]][j + dy[k]];
				if (!p){
					ans[i][j] = dfs(i, j);
					kr[i][j] = koft;
					koft ++ ;
				}
			}
		}
	}
	for(int i = 0; i < n ; i ++){
		for(int j = 0; j < m ; j ++){
			if (ar[i][j] == '.')
				cout << '.';
			else{
				set<int> kk;
				int koftt;
				int p = 0;

				for(int k  = 0; k < 4; k++)
					if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m ){
						koftt = (int)kk.size();
						kk.insert(kr[i + dx[k]][j + dy[k]]);
						if ((int)kk.size() > koftt)
							p += ans[i + dx[k]][j + dy[k]];
					}
				cout << p + 1 ;
			}
		}
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);

const int maxn = 1e3 + 20;
int n , m;
string ar[maxn];
bool mark[maxn][maxn], mark2[maxn][maxn];
int ans[maxn][maxn], dx[] = {-1, 1, 0 , 0}, dy[] = {0, 0, -1, 1},  kr[maxn][maxn], koft = 1;

bool check(int i, int j, int k){
	if (i + dx[k] > -1 && i + dx[k] < n && j + dy[k] > -1 && j + dy[k] < m)
		return 1;
	return 0;
}

int dfs(int i, int j){
	mark[i][j] = 1;
	int ans = 1;
	for(int k = 0; k < 4; k ++){
		if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && !mark[i + dx[k]][j + dy[k]])
			ans += dfs(i + dx[k], j + dy[k]);
	}
	return ans;
}
void dfs2(int i, int j, int o, int oo){
	mark2[i][j] = 1;
	ans[i][j] = o;
	kr[i][j] = oo;
	for(int k = 0; k < 4; k ++){
		if (check(i, j, k) && ar[i + dx[k]][j + dy[k]] == '.' && !mark2[i + dx[k]][j + dy[k]])
			dfs2(i + dx[k], j + dy[k], o, oo);
	}
}
int main(){
	IoFast;
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
		cin >> ar[i];
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < m; j ++){
			if (ar[i][j] == '.'){
				if (ans[i][j] == 0){
					ans[i][j] = dfs(i, j);
					kr[i][j] = koft;
					dfs2(i, j, ans[i][j], koft);
					koft ++ ;
				}
			}
		}
	}
	for(int i = 0; i < n ; i ++){
		for(int j = 0; j < m ; j ++){
			if (ar[i][j] == '.')
				cout << '.';
			else{
				set<int> kk;
				int koftt;
				int p = 0;

				for(int k  = 0; k < 4; k++)
					if (check(i, j, k)){
						koftt = (int)kk.size();
						kk.insert(kr[i + dx[k]][j + dy[k]]);
						if ((int)kk.size() > koftt)
							p += ans[i + dx[k]][j + dy[k]];
					}
				cout << (p + 1) % 10;
			}
		}
		cout << endl;
	}
	//cout << ans[0][1] <<" " << kr[0][1] << endl;
	//cout << ans[1][0] <<" " << kr[1][0] << endl;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define ll long long
#define FILE ""
#define pii pair <int,int>

using namespace std;

const int mod = 1e9 + 7;
const ll inf = 1e18;

char a[1005][1005];
int b[1005][1005],dp[1005][1005],us[1005][1005],mark[1005][1005];

int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> a[i][j];
            b[i][j] = -1;
        }
    }
    int cur = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (!dp[i][j] && a[i][j] == '.') {
                cur++;
                queue <pii> q,good;
                int tmp = 1;
                us[i][j] = 1;
                good.push({i,j});
                q.push({i,j});
                while (!q.empty()) {
                    int x = q.front().F, y = q.front().S;
                    q.pop();
                    if (a[x-1][y] == '.' && !us[x-1][y]) {
                        q.push({x-1,y});
                        good.push({x-1,y});
                        us[x-1][y] = 1;
                        tmp++;

                    }
                    if (a[x+1][y] == '.' && !us[x+1][y]) {
                        q.push({x+1,y});
                        good.push({x+1,y});
                        us[x+1][y] = 1;
                        tmp++;
                    }
                    if (a[x][y-1] == '.' && !us[x][y-1]) {
                        q.push({x,y-1});
                        good.push({x,y-1});
                        us[x][y-1] = 1;
                        tmp++;
                    }
                    if (a[x][y+1] == '.' && !us[x][y+1]) {
                        q.push({x,y+1});
                        good.push({x,y+1});
                        us[x][y+1] = 1;
                        tmp++;
                    }
                }
                while (!good.empty()) {
                    int x = good.front().F, y = good.front().S;
                    good.pop();
                    dp[x][y] = tmp;
                    mark[x][y] = cur;
                }
            }
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (a[i][j] == '*') {
                set <int> kek;
                int tmp = 0;
                if (i > 0 && a[i-1][j] == '.' && !kek.count(mark[i-1][j])) {
                    tmp += dp[i-1][j];
                    kek.insert(mark[i-1][j]);
                }
                if (i < n - 1 && a[i+1][j] == '.' && !kek.count(mark[i+1][j])) {
                    tmp += dp[i+1][j];
                    kek.insert(mark[i+1][j]);
                }
                if (j > 0 && a[i][j-1] == '.' && !kek.count(mark[i][j-1])) {
                    tmp += dp[i][j-1];
                    kek.insert(mark[i][j-1]);
                }
                if (j < m - 1 && a[i][j+1] == '.' && !kek.count(mark[i][j+1])) {
                    tmp += dp[i][j+1];
                    kek.insert(mark[i][j+1]);
                }
                b[i][j] = tmp;
            }
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (b[i][j] == -1) cout << a[i][j];
            else cout << (b[i][j] + 1) % 10;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define ll long long
#define FILE ""
#define pii pair <int,int>

using namespace std;

const int mod = 1e9 + 7;
const ll inf = 1e18;

char a[1005][1005];
int b[1005][1005],dp[1005][1005],us[1005][1005],mark[1005][1005];

int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> a[i][j];
        }
    }
    int cur = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (!dp[i][j] && a[i][j] == '.') {
                cur++;
                queue <pii> q,good;
                int tmp = 1;
                us[i][j] = 1;
                good.push({i,j});
                q.push({i,j});
                while (!q.empty()) {
                    int x = q.front().F, y = q.front().S;
                    q.pop();
                    if (a[x-1][y] == '.' && !us[x-1][y]) {
                        q.push({x-1,y});
                        good.push({x-1,y});
                        us[x-1][y] = 1;
                        tmp++;
                    }
                    if (a[x+1][y] == '.' && !us[x+1][y]) {
                        q.push({x+1,y});
                        good.push({x+1,y});
                        us[x+1][y] = 1;
                        tmp++;
                    }
                    if (a[x][y-1] == '.' && !us[x][y-1]) {
                        q.push({x,y-1});
                        good.push({x,y-1});
                        us[x][y-1] = 1;
                        tmp++;
                    }
                    if (a[x][y+1] == '.' && !us[x][y+1]) {
                        q.push({x,y+1});
                        good.push({x,y+1});
                        us[x][y+1] = 1;
                        tmp++;
                    }
                }
                while (!good.empty()) {
                    int x = good.front().F, y = good.front().S;
                    good.pop();
                    dp[x][y] = tmp;
                    mark[x][y] = cur;
                }
            }
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (a[i][j] == '*') {
                set <int> kek;
                int tmp = 0;
                if (i > 0 && !kek.count(mark[i-1][j])) tmp += dp[i-1][j];
                kek.insert(mark[i-1][j]);
                if (i < n - 1 && !kek.count(mark[i+1][j])) tmp += dp[i+1][j];
                kek.insert(mark[i-1][j]);
                if (j > 0 && !kek.count(mark[i][j-1])) tmp += dp[i][j-1];
                kek.insert(mark[i][j-1]);
                if (j < m - 1 && !kek.count(mark[i][j+1])) tmp += dp[i][j+1];
                kek.insert(mark[i][j+1]);
                b[i][j] = tmp;
            }
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (!b[i][j]) cout << a[i][j];
            else cout << b[i][j] + 1;
        }
        cout << endl;
    }

}