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

int main() {
    int h,w;
    cin >> h >> w;
    string board[50];
    for(int i=0;i<h;i++){
        cin >> board[i];
    }

    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]=='#'){
                continue;
            }
            int num=0;
            for(int k=0;k<8;k++){
                const int ni=i+dy;
                const int nj=j+dx;
                if(ni<0||ni>=h) continue;
                if(nj<0||nj>=w) continue;
                if(board[ni][nj]=='#') num++;
            }
            board[i][j]==char('0'+num);
        }
    }
    for(int i=0;i<h;i++){
        cout << board[i] << endl;
    }
}