#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    string s;
    int Minesweeper[50][50];
    rep(i, H) {
        cin >> s;
        rep(j, W) {
            if (s[j] == '#') {
                Minesweeper[i][j] = 10;
            } else if (s[j] == '.') {
                Minesweeper[i][j] = 0;
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (Minesweeper[i][j] >= 10) {
                if (i == 0) {
                    if (j == 0) {
                        Minesweeper[i][j + 1]++;
                        Minesweeper[i + 1][j]++;
                        Minesweeper[i + 1][j + 1]++;
                    } else if (j == W - 1) {
                        Minesweeper[i][j - 1]++;
                        Minesweeper[i + 1][j - 1]++;
                        Minesweeper[i + 1][j]++;
                    } else {
                        Minesweeper[i][j - 1]++;
                        Minesweeper[i + 1][j - 1]++;
                        Minesweeper[i + 1][j]++;
                        Minesweeper[i][j + 1]++;
                        Minesweeper[i + 1][j + 1]++;
                    }
    
                } else if (i == H - 1) {
                    if (j == 0) {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j + 1]++;
                        Minesweeper[i][j + 1]++;
                    } else if (j == W - 1) {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j - 1]++;
                        Minesweeper[i][j - 1]++;
                    } else {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j - 1]++;
                        Minesweeper[i][j - 1]++;
                        Minesweeper[i - 1][j + 1]++;
                        Minesweeper[i][j + 1]++;
                    }
                } else if (j == 0) {
                    if (i == H - 1) {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j + 1]++;
                        Minesweeper[i][j + 1]++;
                    } else {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j + 1]++;
                        Minesweeper[i][j + 1]++;
                        Minesweeper[i + 1][j + 1]++;
                        Minesweeper[i + 1][j]++;
                    }
                } else if (j == W - 1) {
                    if (i == H - 1) {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j - 1]++;
                        Minesweeper[i][j - 1]++;
                    } else {
                        Minesweeper[i - 1][j]++;
                        Minesweeper[i - 1][j - 1]++;
                        Minesweeper[i][j - 1]++;
                        Minesweeper[i + 1][j - 1]++;
                        Minesweeper[i + 1][j]++;
                    }
                } else {
                    Minesweeper[i - 1][j]++;
                    Minesweeper[i + 1][j]++;
                    Minesweeper[i - 1][j - 1]++;
                    Minesweeper[i][j - 1]++;
                    Minesweeper[i + 1][j - 1]++;
                    Minesweeper[i - 1][j + 1]++;
                    Minesweeper[i][j + 1]++;
                    Minesweeper[i + 1][j + 1]++;
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (Minesweeper[i][j] >= 10) {
                cout << "#";
            } else {
                cout << Minesweeper[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256