n = int(input()) P = list(map(int, input().split())) Q = [0] * n for i, p in enumerate(P, 1): Q[p - 1] = i tot = 0 ans = 0 for i in range(n - 1): tot += Q[i] ans = max(ans, tot - Q[i + 1]) print(ans)