#include<iostream>
#include<cstring>
using namespace std;
char map[101][101];
int t[101][101];
void work(int x,int y)
{
    if(map[x+1][y]=='*') t[x][y]++;
    if(map[x-1][y]=='*') t[x][y]++;
    if(map[x][y+1]=='*') t[x][y]++;
    if(map[x][y-1]=='*') t[x][y]++;
    if(map[x+1][y+1]=='*') t[x][y]++;
    if(map[x+1][y-1]=='*') t[x][y]++;
    if(map[x-1][y+1]=='*') t[x][y]++;
    if(map[x-1][y-1]=='*') t[x][y]++;
}
int main()
{
    int n,m,i,j,k=0;
    cin>>n>>m
        ++k;
        if(n==0||m==0) break;
        for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        cin>>map[i][j];
        for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            if(map[i][j]=='.') work(i,j);
            if(map[i][j]=='*') t[i][j]=-1;
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(t[i][j]==-1) cout<<"*";
                else cout<<t[i][j];
            }
            cout<<endl;
        }
    return 0;
}