#include<iostream>
#include<cstdio>
using namespace std;
int a[51][51];
bool b[51][51];
int main()
{
    int i,j,n,m;
    cin>>n>>m;
    for (i=1;i<=n;i++)
    for (j=1;j<=m;j++)
    {
        char c;
        cin>>c;
        if (c=='#') b[i][j]=1;
    }
    for (i=1;i<=n;i++)
    {
    for (j=1;j<=m;j++)
    if (!b[i][j]) 
    {
        a[i][j]=b[i-1][j-1]+b[i-1][j]+b[i-1][j+1]+b[i][j-1]+b[i][j+1]+b[i+1][j-1]+b[i+1][j]+b[i+1][j+1];
        cout<<a[i][j];
    }
    else cout<<'#';
    cout<<endl;
    }
    return 0;
}