N = int(input()) #初項 a,公差 1,末項 l l = N a = 1 wa = (l - a + 1) * (a + l) // 2 A = list(map(int, input().split())) idx = A.index(N) + 1 takeda = wa - idx suzuki = idx ans = max(takeda - suzuki, 0) #print(N, ans) for i in range(N - 1, 0, -1): idx = A.index(i) + 1 takeda -= idx suzuki = idx #print(i, takeda, suzuki, takeda - suzuki) if max(takeda - suzuki, 0) < ans: print(ans) exit() else: ans = max(takeda - suzuki, 0) print(ans)