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

int main() {
    int H,W;
    cin >> H >> W;
    string S[W];
    for(int i = 0; i < H; ++i) cin >> S[i];

    //*def vector
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

    int num;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            //each cell
            if(S[i][j] == '#') continue;

            //count
            num = 0;
            //with vector
            for (int d = 0; d < 8; ++ d) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];

                if (ni < 0 || H <= ni) continue;
                if (nj < 0 || W <= nj) continue;
                if (S[ni][nj] == ’#’) num++;
            }
            S[i][j] = char(num + ’0’);
            //for(int k = i-1; k <= i+1; ++k){
            //    if(k < 0 || k >= H) continue;
            //    for(int l = j-1; l <= j+1; ++l){
            //        if(l < 0 || l >= W) continue;
            //        if(S[k][l] == '#') num++;
            //    }
            //}
            //S[i][j] = '0' + num;
        }
    }
    for(int i = 0; i < H; ++i) cout << S[i] << endl;
}