#K54762. Find the First Out-of-Order Index

    ID: 29826 Type: Default 1000ms 256MiB

Find the First Out-of-Order Index

Find the First Out-of-Order Index

You are given a list of integers. Your task is to find the first index at which the list is no longer in ascending order. In other words, find the smallest index \(i\) (with \(1 \leq i < n\)) such that \(a_i < a_{i-1}\), where \(a_0, a_1, \ldots, a_{n-1}\) denotes the sequence of numbers. If the sequence is already sorted in non-decreasing order, you must output \(-1\).

Note: The indices are zero-based. That means the first element is at index 0, the second at index 1, and so on.

inputFormat

The input is read from stdin and is given in the following format:

  • The first line contains a single integer \(n\) — the number of elements in the list.
  • The second line contains \(n\) space-separated integers.

If \(n = 0\), the list is empty.

outputFormat

Print a single integer to stdout — the index of the first element that is out of order (i.e. where the current element is smaller than the previous one). If the list is already sorted in ascending order, print \(-1\).

## sample
5
1 2 3 4 5
-1