#include<iostream>
#include<string>
using namespace std;

int main()
{
    int h,w,i,j,s;
    char a[55][55];
    for(i=0;i<55;i++)
    {
        for(j=0;j<55;j++)
            a[i][j]='0';
    }
    cin>>h;cin>>w;
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
        {
            cin>>a[i][j];
        }
        getchar();
    }
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
        {
            s=0;
            if(a[i][j]=='#'){cout<<"#";continue;}
            else
            {
                if(a[i-1][j-1]=='#')s++;
                if(a[i-1][j]=='#')s++;
                if(a[i-1][j+1]=='#')s++;
                if(a[i][j-1]=='#')s++;
                if(a[i][j+1]=='#')s++;
                if(a[i+1][j-1]=='#')s++;
                if(a[i+1][j]=='#')s++;
                if(a[i+1][j+1]=='#')s++;
            }
            cout<<s;
        }
        cout<<endl;
    }
    return 0;
}
