use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut ss = vec![vec!['.'; w + 2]; h + 2];

    for i in 1..h + 1 {
        let s: Vec<char> = read::<String>().chars().collect();
        for j in 1..s.len() {
            ss[i][j] = s[j - 1];
        }
    }

    for i in 1..h + 1 {
        for j in 1..w + 1 {
            if ss[i][j] == '.' {
                let count = [
                    ss[i - 1][j - 1],
                    ss[i - 1][j],
                    ss[i - 1][j + 1],
                    ss[i][j - 1],
                    ss[i][j + 1],
                    ss[i + 1][j - 1],
                    ss[i + 1][j],
                    ss[i + 1][j + 1],
                ];
                print!("{}", count.iter().filter(|&&c| c == '#').count());
            } else {
                print!("#");
            }
        }
        println!();
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}
