h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
S2 = [[0] * (w+2) for i in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            S2[i+1][j+1] = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            s[i][j] = sum(S2[i][j:j+3]) + sum(S2[i+1][j:j+3]) + sum(S2[i+2][j:j+3])
    print(''.join(map(str, s[i])))