Exercise Deadlines

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Bob has N programming exercises that he needs to complete before their deadlines. Exercise i only takes one time unit to complete, but has a deadline di (1 ≤ di ≤ N) time units from now.

Bob will solve the exercises in an order described by a sequence a1, a2, . . . , aN, such that a1 is the first exercise he solves, a2 is the second exercise he solves, and so on. Bob’s original plan is described by the sequence 1, 2, . . . , N. With one swap operation, Bob can exchange two adjacent numbers in this sequence. What is the minimum number of swaps required to change this sequence into one that completes all exercises on time?

입력

The first line consists of a single integer N (1 ≤ N ≤ 200 000). The next line contains N spaceseparated integers d1, d2, . . . , dN (1 ≤ di ≤ N).

출력

Output a single integer, the minimum number of swaps required for Bob to solve all exercises on time, or -1 if this is impossible.