#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i = 0;i<h;i++){
        cin >> s[i];
    }
    
    int count[h][w]={};
    
    for(int j=0;j<h;j++){
        for(int k=0;k<w;k++){
                if(s[j][k]!='#'&&j!=0&&j!=h-1&&k!=0&&k!=w-1){
                    if(s[j-1][k-1]=='#')
                        count[j][k]++;
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j-1][k+1]=='#')
                        count[j][k]++;
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    if(s[j+1][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    if(s[j+1][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j==0&&j!=h-1&&k!=0&&k!=w-1){
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    if(s[j+1][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    if(s[j+1][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j!=0&&j==h-1&&k!=0&&k!=w-1){
                    if(s[j-1][k-1]=='#')
                        count[j][k]++;
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j-1][k+1]=='#')
                        count[j][k]++;
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j!=0&&j!=h-1&&k==0&&k!=w-1){
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j-1][k+1]=='#')
                        count[j][k]++;
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    if(s[j+1][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }    
                if(s[j][k]!='#'&&j!=0&&j!=h-1&&k!=0&&k==w-1){
                    if(s[j-1][k-1]=='#')
                        count[j][k]++;
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                
                if(s[j][k]!='#'&&j==0&&j!=h-1&&k==0&&k!=w-1){
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    if(s[j+1][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j==0&&j!=h-1&&k!=0&&k==w-1){
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k-1]=='#')
                        count[j][k]++;
                    if(s[j+1][k]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j!=0&&j==h-1&&k==0&&k!=w-1){
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j-1][k+1]=='#')
                        count[j][k]++;
                    if(s[j][k+1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                if(s[j][k]!='#'&&j!=0&&j==h-1&&k!=0&&k==w-1){
                    if(s[j-1][k-1]=='#')
                        count[j][k]++;
                    if(s[j-1][k]=='#')
                        count[j][k]++;
                    if(s[j][k-1]=='#')
                        count[j][k]++;
                    s[j][k]=(char)count[j][k];
                }
                
        }
        
    }
    for(int a = 0;a<h;a++){
        for(int b = 0;b<w;b++){
            if(s[a][b]=='#'){
                printf("#");
            }else{
                printf(" %d",count[a*w+b]);
            }
        }
        printf("\n");
        
    }
    return 0;
}