H, W = map(int, input().split())
S = [input() for i in range(H)]
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            cnt = 0
            for k in range(8):
                if(i+dy[k] >= 0 and i+dy[k] < H and j+dx[k]>0 and j+dx[k] < W and S[i+dy[k]][j+dx[k]]=='#'):
                    cnt+=1
            print(cnt, end='')
        else:
            print(S[i][j], end='')
    print('')


