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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s.at(i);
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c = s[i][j];
            
            if(c == '.') s[i][j] = 0;
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c = s[i][j];
            
            if(c == '#') {
                if(j != w - 1) s[i][j+1]++;
                if(j != 0 ) s[i][j-1]++;
                if(i != 0) {
                    s[i-1][j]++
                    if(j != w - 1) s[i-1][j+1]++;
                    if(j != 0 ) s[i-1][j-1]++;
                }
                if(i != h - 1) {
                    s[i+1][j]++
                    if(j != w - 1) s[i+1][j+1]++;
                    if(j != 0 ) s[i+1][j-1]++;
                }
            }
        }
    }

    for (int i = 0; i < h; i++) {
        cout << s.at(i) << endl;
    }

    return 0;
}