#include <bits/stdc++.h>
using namespace std;

int main(){
    int H,W; cin>>H>>W;
    vector<string> V(H);
    for(auto&v:V)cin>>v;

    int n_x, n_y;
    for(int i=0;i<H;i++, puts("")){
        for(int j=0;j<W;j++){
            if(V[i][j]=='#'){cout<<"#"; continue;}
            V[i][j] = '0';
            for(int dy=-1;dy<=1;dy++)for(int dx=-1;dx<=1;dx++){
                n_y = i + dy; n_x = j + dx;
                if(n_x>=0 && n_x<W && n_y>=0 && n_y<H && V[n_y][n_x]=='#')V[i][j]++;
            }
        cout<<V[i][j];
        }
    }
}