#!/usr/local/gnu/bin/bash
read h w
s=(`tr '.#' '01'`)
for i in `seq 0 $((h-1))`
do
    for j in `seq 0 $((w-1))`
    do
        if((${s[i]:j:1}))
        then
            echo -n "#"
            continue
        fi
        c=0
        if((i>0))
        then
            ((j>0)) && c=$((c+${s[i-1]:j-1:1}))
            c=$((c+${s[i-1]:j:1}))
            ((j<w-1)) && c=$((c+${s[i-1]:j+1:1}))
        fi
        ((j>0)) && c=$((c+${s[i]:j-1:1}))
        ((j<w-1)) && c=$((c+${s[i]:j+1:1}))
        if((i<h-1))
        then
            ((j>0)) && c=$((c+${s[i+1]:j-1:1}))
            c=$((c+${s[i+1]:j:1}))
            ((j<w-1)) && c=$((c+${s[i+1]:j+1:1}))
        fi
        echo -n $c
    done
    echo
done
