import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
import std.math;
import std.range;
 
void main() {
    auto tmp = readln.split.to!(int[]);
    auto H = tmp[0], W = tmp[1];
    char[][] S;
    foreach (i; 0..H) {
        S ~= readln.chomp.dup;
    }
    foreach (i; 0..W) {
        foreach (j; 0..H) {
            if (S[j][i] == '#') continue;
            auto c = 0;
            foreach (k; -1..2) {
                if (i+k == -1) continue;
                if (i+k == W) continue;
                foreach (l; -1..2) {
                    if (j+l == -1) continue;
                    if (j+l == H) continue;
                    if (S[j+l][i+k] == '#') c++;
                }
            }
            S[j][i] = cast(char)(c + '0');
        }
    }
    foreach (i; 0..H) {
        writeln(S[i]);
    }
}
