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; var list = a.Distinct().ToList(); list.Sort(); var dic = new Dictionary(); for (var i = 0; i < list.Count; ++i) dic[list[i]] = i; var b = new int[n]; for (var i = 0; i < n; ++i) b[i] = dic[a[i]]; var inv = 0; for (var i = 0; i + 1 < n; ++i) { if (b[i] > b[i + 1]) { ++inv; if (b[i + 1] > 0) ++inv; } } WriteLine(Math.Min(2, inv)); } }