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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char c[h + 2][w + 2] = {'*'};
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> c[i][j];
        }
    }
    int x8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
    int y8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (c[i][j] == '.') {
                int b = 0;
                for (int k = 0; k < 8; k++) {
                    if (c[i + x8[k]][j + y8[k]] == '#') b++;
                }
                c[i][j] = to_string(b).at(0);
            }
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cout << c[i][j];
        }
        cout << "\n";
    }
    return 0;
}