#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> shuzu(n, vector<char> (m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> shuzu[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (shuzu[i][j] == '*') {
                cout << "*";
                continue;
            } else {
                int shu = 0;
                for (int z = i - 1; z <= i + 1; z++) {
                    for (int x = j - 1; x <= j + 1; x++) {
                        if (z < 0 || z > n - 1 || x < 0 || x > m - 1){
                            continue;
                        }
                        if (shuzu[z][x] == '*') {
                            shu++;
                        }
                    }
                }
                cout << shu;
            }
        }
        cout << endl;
    }
}
// 64 位输出请用 printf("%lld")