void main() {
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1];
    dchar[][] s = new dchar[][](h, w);
    foreach (i; 0 .. h) {
        string row = readln.chomp;
        foreach (j, c; row) {
            s[i][j] = c;
        }
    }
    int[8] dx = [0, 1, 1, 1, 0, -1, -1, -1];
    int[8] dy = [1, 1, 0, -1, -1, -1, 0, 1];
    foreach (i; 0 .. h) {
        foreach (j; 0 .. w) {
            if (s[i][j] =='#') continue;
            int cnt;
            foreach (k; 0 .. 8) {
                int x = j + dx[k];
                int y = i + dy[k];
                if (x < 0 || w <= x) continue;
                if (y < 0 || h <= y) continue;
                if (s[y][x] == '#') ++cnt;
            }
            s[i][j] = cnt.to!string.to!dchar;
        }
    }
    foreach (y; s) {
        y.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;