#include <iostream>
#include <vector>
#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int H, W;
    std::cin >> H >> W;

    std::vector<std::vector<char>> S;
    S.assign(H + 2, std::vector<char>(W + 2, '_'));
    for (int i = 1; i <= H; i ++) {
        for (int j = 1; j <= W; j ++) {
            std::cin >> S[i][j];
        }
    }

    for (int i = 1; i <= H; i ++) {
        for (int j = 1; j <= W; j ++) {
            if (S[i][j] == '.') {
                int count =
                        (S[i - 1][j - 1] == '#') + (S[i - 1][j] == '#') + (S[i - 1][j + 1] == '#') +
                        (S[i][j - 1] == '#') + (S[i][j + 1] == '#') +
                        (S[i + 1][j - 1] == '#') + (S[i + 1][j] == '#') + (S[i + 1][j + 1] == '#');
                std::cout << count;
            } else {
                std::cout << S[i][j];
            }
        }
        std::cout << std::endl;
    }
}
