import itertools
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
l=list(itertools.product([-1,0,1],repeat=2))

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            cnt = 0
            for k in l:
                x = min(max(0,i+k[0]),h-1)
                y = min(max(0,j+k[1]),w-1)
                if s[x][y]=='#':
                    cnt+=1
            s[i][j]=str(cnt)
for i in s:
    print(''.join(i))