H,W = map(int,input().split())
S = [input() for _ in range(H)] 

nS = [['' for i in range(W)] for j in range(H)]

cpC = [1, 0, -1, 0, 1, -1, -1, 1]
cpR = [0, 1, 0, -1, 1, 1, -1, -1]


for i in range(H):
    for j in range(W):
        counter = 0
        if S[i][j] == '#':
            nS[i][j] = '#'
            continue

        for r,c in zip(cpR,cpC):
            try:
                if S[i+r][j+c] == '#':
                    counter += 1
            except:
                continue
        
        nS[i][j] = counter

for i in range(H):
    for j in range(W):
        print(nS[i][j], end="")
    print('')

