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

for y in range(1, H+1):
    for x in range(1, W+1):
        if S[y][x] == '.':
            S[y][x] = str(len([1 for i in range(y-1, y+2) for j in range(x-1, x+2) if S[i][j] == '#']))

S = [s[1:-1] for s in S[1:-1]]

[print(''.join(s)) for s in S]