import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable mod = 10^^9 + 7;

void main() {
    int h, w;
    scan(h, w);

    auto map = new char[][](h + 2, w + 2);
    iota(h).each!(i => map[i + 1][1 .. w + 1] = readln.chomp.to!(char[]));

    auto dx = [1, 0, -1, 0, 1, 1, -1, -1], dy = [0, 1, 0, -1, 1, -1, 1, -1];

    foreach (i ; 1 .. h + 1) {
        foreach (j ; 1 .. w + 1) {
            if (map[i][j] == '.') {
                int cnt;
                foreach (k ; 0 .. 8) {
                    cnt += (map[i + dx[k]][j + dy[k]] == '#');
                }
                map[i][j] = ('0' + cnt).to!char;
            }
        }
    }

    iota(h).each!(i => writeln(map[i + 1][1 .. w + 1]));
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}