<?php
fscanf(STDIN, "%d %d", $h, $w);
$arr = [];
// 入力取得
for($i = 0; $i < $h; $i++) {
    fscanf(STDIN, "%s", $s);
    $arr[$i] = str_split($s);
}
//var_dump($arr);
$dx = [-1, 0, 1, -1, 1, -1, 0, 1];
$dy = [1, 1, 1, 0, 0, -1, -1, -1];
for($j = 0; $j < $h; $j++) {
    for($k = 0; $k < $w; $k++) {
        $num = 0;
        if($arr[$j][$k] == "#") {
            continue;
        } else {
            for($l = 0; $l < 8; $l++) {
                $dlx = $k + $dx[$l];
                $dly = $j + $dy[$l];
//var_dump($dlx, $dly);
                if($dly < 0 || $dly >= $h) continue;
                if($dlx < 0 || $dlx >= $w) continue;
                if($arr[$dly][$dlx] == "#") $num++;
            }
        }
        $arr[$j][$k] = $num;
    }
}
foreach($arr as $row) {
    foreach($row as $v) {
        echo $v;
    }
    echo "\n";
}