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

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int);
}

/// 数の読み込み
auto readNum() {
	return readNums.front;
}

void main() {
    const nums = readNums.array;
    immutable h = nums[0];
    immutable w = nums[1];

	const field = generate(() => readln).map!strip.take(h).array;

    char[][] answer = [];
    answer.length = h;
    foreach(ref s; answer) {
        s.length = w;
    }

    foreach(y; 0 .. h) {
        foreach(x; 0 .. w) {
            if(field[y][x] == '#') {
                answer[y][x] = '#';
                continue;
            }

            size_t n = 0;
            immutable left = (x == 0);
            immutable right = (x == w - 1);
            immutable top = (y == 0);
            immutable bottom = (y == h - 1);

            n += (!left && (field[y][x - 1] == '#')) ? 1 : 0;
            n += (!right && (field[y][x + 1] == '#')) ? 1 : 0;
            n += (!top && (field[y - 1][x] == '#')) ? 1 : 0;
            n += (!top && !left && (field[y - 1][x - 1] == '#')) ? 1 : 0;
            n += (!top && !right && (field[y - 1][x + 1] == '#')) ? 1 : 0;
            n += (!bottom && (field[y + 1][x] == '#')) ? 1 : 0;
            n += (!bottom && !left && (field[y + 1][x - 1] == '#')) ? 1 : 0;
            n += (!bottom && !right && (field[y + 1][x + 1] == '#')) ? 1 : 0;
            answer[y][x] = cast(char)('0' + cast(int) n);
        }
    }

    answer.each!writefln;
}