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;

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

            int bomb = 0;
            for (int dr = -1; dr <= 1; dr++) {
                for (int dc = -1; dc <= 1; dc++) {
                    if (dr == 0 && dc == 0)
                        continue;

                    int r = i + dr;
                    int c = j + dc;
                    if (0 <= r && r < rows && 0 <= c && c < cols) {
                        if (ss[r][c] == '#') {
                            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);
}
