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

void main()
{
    auto input = readln.chomp.split.to!(int[]);
    auto H = input[0];
    auto W = input[1];

    auto S = new string[H];
    foreach(ref i ; S)
        i = readln.chomp.to!string;
    
    int[8] dx = [-1, 1, 0, 0, -1, -1, 1, 1];
    int[8] dy = [0, 0, -1, 1, -1, 1, -1, 1];
    foreach(i ; 0..H){
        foreach(int j ; 0..W){
            if(S[i][j] == '.'){
                int count = 0;
                foreach(k ; 0..8){
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if(0 <= nx && nx < W && 0 <= ny && ny < H && S[ny][nx] == '#'){
                        count++;
                    }
                }
                count.write;
            }
            else S[i][j].write;
        }
        writeln;
    }
}