h,w = map(int, input().split())
x = [list(input()) for _ in range(h)]
y = [[0]*(w+2) for _ in range(h+2)]

for i in range(h):
    for j in range(w):
        if x[i][j] == '.':
            y[i+1][j+1] = 0
        else:
            y[i+1][j+1] = 1

for i in range(h):
    for j in range(w):
        if x[i][j] == '.':
            x[i][j] = str(sum(y[i][j:j+3])+sum(y[i+1][j:j+3])+sum(y[i+2][j:j+3]))
    print(''.join(x[i]))