import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void calc(string[] ss) {
    int rows = cast(int) ss.length;
    int cols = cast(int) ss[0].length;

    int[][] adj(int row, int col) { // 隣接 8 マス
        auto dr = [-1, -1, -1, 0, 0, 1, 1, 1];
        auto dc = [-1, 0, 1, -1, 1, -1, 0, 1];

        int[][] ret;
        for (int i = 0; i < dr.length; i++) {
            int r = dr[i] + row;
            int c = dc[i] + col;
            if (0 <= r && r < rows && 0 <= c && c < cols)
                ret ~= [r, c];
        }
        return ret;
    }

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (ss[i][j] == '#') {
                write('#');
                continue;
            }

            int bomb = 0;
            foreach (e; adj(i, j)) {
                if (ss[e[0]][e[1]] == '#')
                    bomb++;
            }
            write(bomb);
        }
        writeln;
    }
}

void main() {
    auto hw = readints;
    int rows = hw[0];
    string[] ss;
    for (int i = 0; i < rows; i++) {
        ss ~= readln.chomp;
    }

    calc(ss);
}
