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

void main(){
    auto HW = readln.split.to!(int[]);
    auto board = iota(HW[0]).map!(_ => readln.chomp.to!(dchar[])).array;

    auto hit(in int[] yx){
        auto y = yx[0];
        if(y < 0 || HW[0] <= y) return false;
        auto x = yx[1];
        if(x < 0 || HW[1] <= x) return false;
        return board[y][x] == '#';
    }

    auto countHit(in int y, in int x){
        return cartesianProduct([-1, 0, 1], [-1, 0, 1])
            .map!(diff => diff.array[] += [y, x])
            .count!(at => hit(at));
    }

    foreach(int y, ref line; board)
        foreach(int x, ref c; line){
            if(c != '.')continue;
            c = countHit(y, x).to!string.front;
        }
    writeln(board.join('\n'));
}