H, W = map(int, input().split())


ans = []
for i in range(H):
    ans.append([])
    row = input()
    for j in row:
        ans[-1].append(j)

dxy = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]

for y in range(H):
    for x in range(W):
        if ans[y][x] == '#':
            continue
        c = 0
        for dx, dy in dxy:
            if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy>H-1:
                continue
            if ans[y+dy][x+dx] == '#':
                c += 1
            ans[y][x] = c
        
for row in ans:
    print(''.join(list(map(str, row))))