#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    getchar();
    char str[x][y];
    for(int i=0;i<x;i++)
    {
        for(int j=0;j<y;j++)
        {
            scanf("%c",&str[i][j]);
        }
        getchar();
    }
    for(int i=0;i<x;i++)
    {
        for(int j=0;j<y;j++)
        {
            int k=0;
            if(str[i][j]!='*')
            {
                if(i-1>=0&&str[i-1][j]=='*')
                {
                k++;
                }
                if(i-1>=0&&j-1>=0&&str[i-1][j-1]=='*')
                {
                k++;
                }
                if(j-1>=0&&str[i][j-1]=='*')
                {
                    k++;
                }
                if(i-1>=0&&j+1<y&&str[i-1][j+1]=='*')
                {
                    k++;
                }
                if(j+1<y&&str[i][j+1]=='*')
                {
                    k++;
                }
                if(i+1<x&&j-1>=0&&str[i+1][j-1]=='*')
                {
                    k++;
                }
                if(i+1<x&&str[i+1][j]=='*')
                {
                    k++;
                }
                if(i+1<x&&j+1<y&&str[i+1][j+1]=='*')
                {
                    k++;
                }
                printf("%d",k);
        }
            else
                printf("*");
    }
        printf("\n");
}
    return 0;
}