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

int main()
{
        int H, W;
        cin >> H >> W;
        string S[H];
        for (int i = 0; i < H; ++i) {
                cin >> S[i];
        }
        int out[H][W];
        int index1 = 0;
        int index2 = 0;
        for  (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                        if (S[i][j] == '#') {
                                out[i][j] = -1;
                                continue;
                        }
                        int bom = 0;
                        index1 = i - 1;
                        index2 = j - 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index2 = j;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index2 = j + 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index1 = i;
                        index2 = j - 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index2 = j + 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index1 = i + 1;
                        index2 = j - 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index2 = j;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        index2 = j + 1;
                        if (index1 >= 0 && index2 >= 0 && index1 < H && index2 < W) {
                                if (S[index1][index2] == '#') {
                                        bom++;
                                }
                        }
                        out[i][j] = bom;
                }
        }
        for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                        if (out[i][j] == -1) {
                                cout << "#";
                        }
                        else {
                                cout << out[i][j];
                        }
                }
                cout <<  endl;
        }
}


Measured memory_bytes: 256