#include <iostream>
using namespace std;
int main(void){
    int h,w;
    cin >> h >> w;
    
    string s[50];
    for(int i = 0;i < h;i++) cin >> s[i];
    
    int dx[8] = {1,1,1,0,0,-1,-1,-1};
    int dy[8] = {0,1,-1,1,-1,0,1,-1};
    
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(string[i][j] == '#') continue;
            
            int num = 0;
            for(int k = 0;k < 8;k++){
                int ny = i + dx[k];
                int nj = j + dy[k];
                
                if(ni < 0 || h <= ni) continue;
                if(nj < 0 || w <= nj) continue;
                if(s[i][j] == '#') num++;
            }
            s[i][j] = char(num + '0');
        }
    }
    for(int i = 0;i < h;i++) cout << s[i] << endl;
    return 0;
}