h,w=map(int,input().split());a=[list(input())for _ in[0]*h]
for y in range(h):
    for x in range(w):
        c=0
        if a[y][x]=='.':
            for i in range(8):
                u=x+[-1,-1,-1,0,0,1,1,1][i];v=y+[-1,0,1,-1,1,-1,0,1][i]
                if 0<=u<w and 0<=v<h and a[v][u]=='#':c+=1
            a[y][x]=c
for i in range(h):print(*a[i],sep='')