#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H+2);
    vector<vector<int>> memo;
    int s;
    for (int i = 1; i <= H; i++)
    {
        S[i].push_back('.')
        for (int j = 1; j <= W; j++)
        {
            cin >> s;
            S[i].push_back(s)
            if (s == '.'){
            memo.push_back({i,j})
            }
        }
        S[i].push_back('.')
    }
    int tmp;
    for (int i = ; i < memo.size(); i++){
        for (int j = -1; j <= 1; j++){
            for (int k = -1; k <= 1; k++){
                if (S[memo[i][0] + j][memo[i][1] + k] == '#' ){
                    tmp++;
                }
            }
        }
        S[memo[i][0]][memo[i][1]] = char(tmp);

    }
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cout << S[i][j] << endl;
        }
    }
}
