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 print(max(wa - idx * 2, 0))