h,w = map(int, input().split())
S = [input() for _ in range(h)]
for r in range(h):
    for c in range(w):
        count = 0
        if S[r][c] == '#':
            print('#', end='')
        else:
            for x in S[max(0,r-1):min(r+2,h)]:
                count += x[max(0,c-1):min(c+2,w)].count('#')
            print(count, end='')
    print()