#include<bits/stdc++.h>
using namespace std;
int n,m,x,b[1000][1000];
int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; ++i)
    for (int j=1; j<=m; ++j)
    {
        cin>>x;
        if (x=='#') {b[i][j]=-1; b[i][j+1]++; b[i+1][j]++; b[i+1][j+1]++; b[i-1][j]++; b[i][j-1]++; b[i-1][j-1]++; b[i-1][j+1]++; b[i+1][j-1]++;
    }
    for (int i=1; i<=n; ++i)
    for (int j=1; j<=m; ++j)
    if (b[i][j]==-1) cout<<'#'<<endl;
    else cout<<b[i][j]<<endl;
    return 0;
}