from sys import stdin n, *a = map(int, stdin.read().split()) asort = [] for i in range(n): asort.append((-a[i],i+1)) asort.sort() ans = 0 val = n * (n+1) // 2 for i in range(n): val -= asort[i][1] ans = max(ans,val-asort[i][1]) print("{}".format(ans))