H,W=map(int, input().split())

S=[input() for _ in range(H)]

ans =[]

for i in range(H):
    s = ''
    for j in range(W):
        if S[i][j] != '#':
            cnt = 0
            for k in range(-1, 2):
                for m in range(-1, 2):
                    col = i + k
                    row = j + m
                    if (col < 0 or row < 0 or col >= H-1 or row >= W-1) or (k == 0 and m == 0):
                        continue
                    else:
                        if S[col][row] == '#':
                            cnt += 1
            s += str(cnt)
        else:
            s += '#'
    ans.append(s)

for i in range(H):
    print(ans[i])

