import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val a = Array(n) { sc.nextInt() } // a[i],...,a[n-1]がソートされているかどうか val isSorted = Array(n) { false } // a[0],...,a[i]における減少回数 val decrease = Array(n) { 0 } // a[0],...,a[i]の最大値 val max = Array(n) { a[0] } isSorted[n - 1] = true for (i in n - 2 downTo 0) { if (a[i] <= a[i + 1]) { isSorted[i] = true } else { break } } if (isSorted[0]) { println(0) return } for (i in 1 until n) { decrease[i] = decrease[i - 1] if (a[i - 1] > a[i]) decrease[i]++ max[i] = maxOf(max[i - 1], a[i]) } for (i in 0 until n) { if (decrease[i] == 1 && a[i] <= a[0] && i == n - 1) { println(1) return } if (decrease[i] == 1 && a[i] <= a[0] && isSorted[i + 1] && max[i] <= a[i + 1]) { println(1) return } } println(2) } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() fun ready() = br.ready() }