h, w = map(int, input().split())
before = [input() for s in range(h)]

after = []
for i in range(h):
    row = ''
    for j in range(w):
        tmp = ''
        if before[i][j] == '.':
            for i2 in (i-1, i, i+1):
                for j2 in (j-1, j, j+1):
                    if i2 == i and j2 == j:
                        continue
                    else:
                        try:
                            tmp += before[i2][j2]
                        except IndexError:
                            tmp += '.'
            row += str(tmp.count('#'))
        else:
            row += '#'
    after.append(row)

for row in after:
    print(row)
