#C9230. Minimum Operations to Sort Sequence

    ID: 53301 Type: Default 1000ms 256MiB

Minimum Operations to Sort Sequence

Minimum Operations to Sort Sequence

You are given a sequence of integers of length \( n \). You are allowed to perform an operation where you select a contiguous subarray and sort it in non-decreasing order. Your task is to determine the minimum number of such operations required to make the entire sequence sorted in non-decreasing order.

If the sequence is already sorted, no operations are required. Otherwise, a single operation is always sufficient to sort the sequence.

Note: The sequence is considered sorted if for every \( i \) (\(1 \leq i < n\)), \( a_i \leq a_{i+1} \).

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a single integer \( n \) (\(1 \leq n \leq 1000\)).
  2. The second line contains \( n \) space-separated integers \( a_1, a_2, \dots, a_n \) (\(1 \leq a_i \leq 1000\)).

outputFormat

Output to standard output (stdout) a single integer representing the minimum number of operations required to sort the sequence in non-decreasing order.

## sample
5
1 3 2 5 4
1