//https://atcoder.jp/contests/abc075/tasks/abc075_b

#include <iostream>
using namespace std;

int main(){
    __int64 H,W;
    int counter = 0;
    // string S[51][51];
    string S[51];

    cin >> H >> W;
    for (int i = 0; i < H; i++){
        cin >> S[i];
    }
    for (int i = 0; i < H; i++){
            // cout << S[i] << endl;
    }
    // string num[H][W];
    int num[H][W];
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            num[H][W] = 0;
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            counter = 0;
            // if (S[i][j] == '.') printf("S[%d][%d]=clear\r\n",i,j);
            if (S[i][j] == '.'){
                for (int p = i-1; p <= i+1; p++){
                    for (int q = j-1; q <= j+1; q++){
                        if(p < 0 || q < 0 || p >= H || q >= W){
                            ;
                        }else{
                            if (S[p][q] == '#'){
                                counter ++;
                            }
                        }
                    }
                }
                num[i][j] = counter;
                // printf("num[%d][%d] = %d\r\n",i,j,num[i][j]);
            }
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if (S[i][j] == '.'){
                S[i][j] = '0' + num[i][j];
            }
        }
    }
    for (int i = 0; i < H; i++) {
        cout << S[i] << endl;
    }
}