#!/bin/bash

read H W
arr=()
for i in `seq ${H}`; do
    read st
    arr+=($st)
done

ans=()
for i in `seq 0 $((H-1))`; do
    ansline=''
    for j in `seq 0 $((W-1))`; do
        tl=${arr[$i]}
        t=${tl:j:1}
        # echo "${i}, ${j}, ${tl}, ${tl:j:1}"
        if [ ${t} = '#' ]; then 
            ansline=${ansline}'#'
        else
            cnt=0
            for k in `seq -1 1`; do
                al=${arr[$((i+k))]}
                for l in `seq -1 1`; do
                    a=${al:$((j+l)):1}
                    if [[ ${a} = '#' ]]; then
                        let cnt++
                    fi
                done
            done
            ansline=${ansline}${cnt}
        fi
    done
    echo ${ansline} 
done
