h,w=map(int,input().split())
M=[]
for i in range(h):
    l=list(input().replace('.','0').replace('#','9'))
    l=list(map(int,l))
    M.append(l)
for i in range(h):
    for j in range(w):
        if M[i][j]==9:
            M[i][j]='#'
            if i+1 in range(h):
                M[i+1][j]+=1
            if i-1 in range(h):
                M[i-1][j]+=1
            if j+1 in range(w):
                M[i][j+1]+=1
            if j-1 in range(w):
                M[i][j-1]+=1
for i in range(h):
    print(*M[i],sep='')