H, W = map(int, input().split())
S = [input() for _ in range(H)]

for i in range(H):
    l = ''
    for j in range(W):
        if S[i][j] == '#':
            l += '#'
        else:
            l += str(sum([s[max(0, j-1):min(W, j+2)].count('#') for s in S[max(0, i-1):min(H, i+2)]]))
    print(l)