fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn main() {
    let (h, w) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        let v = buf
            .trim()
            .split_whitespace()
            .map(|e| e.trim().parse().ok().unwrap())
            .collect::<Vec<usize>>();
        (v[0], v[1])
    };

    let mut s: Vec<Vec<char>> = (0..h)
        .map(|_| read::<String>().chars().rev().collect())
        .collect();

    let bom: char = "#".to_owned().chars().next().unwrap();
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == bom {
                continue;
            }
            let mut cnt = 0;
            if i > 0 {
                if j > 0 {
                    if s[i - 1][j - 1] == bom {
                        cnt += 1;
                    }
                }

                if s[i - 1][j] == bom {
                    cnt += 1;
                }

                if j < w - 1 {
                    if s[i - 1][j + 1] == bom {
                        cnt += 1;
                    }
                }
            }

            if j > 0 {
                if s[i][j - 1] == bom {
                    cnt += 1;
                }
            }

            if j < w - 1 {
                if s[i][j + 1] == bom {
                    cnt += 1;
                }
            }

            if i < h - 1 {
                if j > 0 {
                    if s[i + 1][j - 1] == bom {
                        cnt += 1;
                    }
                }

                if s[i + 1][j] == bom {
                    cnt += 1;
                }

                if j < w - 1 {
                    if s[i + 1][j + 1] == bom {
                        cnt += 1;
                    }
                }
            }
            s[i][j] = cnt.to_string().chars().next().unwrap();
        }
        println!("{}", s[i].iter().collect::<String>());
    }
}
