h,w=map(int,input().split())
s=[input() for _ in [0]*h]
l=[]
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':l.extend([[i,j]])
a=''
for i in range(h):
    for j in range(w):
        if [i,j] in l:a+='#'
        else:
            c=0
            for m in l:
                if abs(i+j-sum(m))+abs(i-j-m[0]+m[1])==2:c+=1
            a+=str(c)
for i in range(h):print(a[w*i:w*(i+1)])