H, W = map(int, input().split())
S = [input() for _ in range(H)]
newS = [['#' for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            c = max(0, j-1)
            d = min(W-1, j+1)
            if i == 0:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i+1][c:d+1].count('#')
            elif i == H-1:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i-1][c:d+1].count('#')
            else:
                cnt = S[i][c:d+1].count('#')
                cnt += S[i-1][c:d+1].count('#')
                cnt += S[i+1][c:d+1].count('#')
            newS[i][j] = str(cnt)
for i in newS:
    print(''.join(i))
