def get_bomb_num(i, j):
    cnt = 0
    for p in range(-1,2):
        for s in range(-1,2):
            l = i + p
            m = j + s
----
            if (p == 0 and s == 0) or (l < 0) or (l >= H) or (m < 0) or (m >= W):
                continue--
            if b[l][m] == '#':
                cnt += 1
    return cnt

H,W = list(map(int, input().split()))
b =[]
for i in range(H):
    b.append(str(input()))

for i in range(H):
    for j in range(W):
        if b[i][j] == '#':
            print('#', end ='')
        else:
            print(get_bomb_num(i,j), end='')
    print('')