h, w = map(int, input().split())
s = ['.' + input() + '.' for i in range(h)]
s.insert(0, '.' * (w+2))
s.append('.' * (w+2))

def search(x, y):
    return sum((s[x + i][y + j] == '#') +0 for i in range(-1, 2) for j in range(-1, 2))

for i in range(1, h + 1):
    for j in range(1, w + 1):
        print(search(i, j) if s[i][j] == '.' else '#', end='')
    print()