using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; WriteLine(Cyclic(n, a)); } static int Cyclic(int n, int[] a) { var inv = 0; var minp = 0; for (var i = 0; i + 1 < n; ++i) { if (a[i] > a[i + 1]) { minp = i + 1; ++inv; } } if (inv > 1) return 2; if (minp == 0) { for (var i = 0; i + 1 < n; ++i) { if (a[i] > a[i + 1]) { return 2; } } return 0; } else { for (var i = 0; i + 1 < n; ++i) { if (i + 1 != minp && a[i] > a[i + 1]) { return 2; } } var maxp = n; for (var i = minp; i < n; ++i) { if (a[minp - 1] <= a[i]) { maxp = i; break; } } var b = a.Skip(minp).Take(maxp - minp).Concat(a.Take(minp)).Concat(a.Skip(maxp)).ToArray(); for (var i = 0; i + 1 < n; ++i) { if (b[i] > b[i + 1]) return 2; } return 1; } } }