#include<stdio.h>
int main()
{
    char ch[51][51];
    int count,i,j,H,W;
    scanf("%d %d",&H,&W);
    ch[0][0]=getchar();
    for(i=0;i<H;i++)
    {
        for(j=0;j<W;j++)
            scanf("%c",&ch[i][j]);
        ch[i+1][0]=getchar();
    }
    for(i=0;i<H;i++)
    {
        count=0;
        for(j=0;j<W;j++)
        {
            count=0;
            if(ch[i][j]=='.')
            {
                if(ch[i-1][j]=='#')
                   count++;
                if(ch[i-1][j+1]=='#')
                   count++;
                if(ch[i][j+1]=='#')
                   count++;
                if(ch[i+1][j+1]=='#')
                   count++;
                if(ch[i+1][j]=='#')
                   count++;
                if(ch[i+1][j-1]=='#')
                   count++;
                if(ch[i][j-1]=='#')
                   count++;
                if(ch[i-1][j-1]=='#')
                   count++;
                ch[i][j]=count+'0';
            }
        }
    }
    for(i=0;i<H;i++)
 