import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) res = 0 table = [0] * (N + 1) for i in range(N): table[a[i]] = i + 1 sm = 0 for i in range(N): sm += table[i] res = max(res, sm - table[i + 1]) print(res)