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

d = [['#']*W]*H
cnt = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
#            continue
#            print(i,j)
            d[i][j] = '#'
        else:
            if i-1>=0 and S[i-1][j] == '#':
                cnt += 1
            if i-1>=0 and j-1>=0 and S[i-1][j-1] == '#':
                cnt += 1
            if i-1>=0 and j+1<W and S[i-1][j+1] == '#':
                cnt += 1
            if i-1>=0 and S[i][j-1] == '#':
                cnt += 1
            if j+1<W and S[i][j+1] == '#':
                cnt += 1
            if i+1<H and S[i+1][j] == '#':
                cnt += 1
            if i+1<H and j-1>=0 and S[i+1][j-1] == '#':
                cnt += 1
            if i+1<H and j+1<W and S[i+1][j+1] == '#':
                cnt += 1
            S[i][j] = str(cnt)
        cnt = 0

for i in range(H):
    print(''.join(S[i]))