<?php
fscanf(STDIN, "%d %d", $H, $W);
$field = array();
for($i=0;$i<$H;$i++){
    $field[] = str_split(trim(fgets(STDIN)));
}
$dx = [1,0,-1,0,1,-1,-1,1];
$dy = [0,1,0,-1,1,1,-1,-1];

for($i=0;$i<$H;$i++){
    for($j=0;$j<$W;$j++){
        if($field[$i][$j] == "#") continue;
        $cnt=0;
        for($d=0;$d<8;$d++){
            $ni = $i+$dy[$d];
            $nj = $j+$dx[$d];
            if($ni < 0 || $H <= $ni) continue;
            if($nj < 0 || $W <= $nj) continue;
            if($field[$ni][$nj] == '#') $cnt++;
        }
        $field[$i][$j] = $cnt;
    }
}

foreach($field as $field_x){
    foreach($field_x as $field){
        echo $field;
    }
    echo "\n";
}