#include <iostream>
using namespace std;
int main()
{
    int H,W;
    cin>>H>>W;
    char s[H][W];
    for(int i=0;i<H;i++)
    {
        cin>>s[i];
    }
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(s[i][j]!='#')
                {
                    int c=0;
                    if(i>0&&j>0&&s[i-1][j-1]=='#')c++;
                    if(j>0&&s[i][j-1]=='#')c++;
                    if(i<H-1&&j>0&&s[i+1][j-1]=='#')c++;
                    if(i>0&&s[i-1][j]=='#')c++;
                    if(i<H-1&&s[i+1][j]=='#')c++;
                    if(i>0&&j<W-1&&s[i-1][j+1]=='#')c++;
                    if(j<W-1&&s[i][j+1]=='#')c++;
                    if(i<H-1&&j<W-1&&s[i+1][j+1]=='#')c++;
                    cout<<c;
                }
            else cout<<'#';
        }
        if(i<H-1)cout<<endl;
    }
}
