import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int [n]; for(int i= 0; i< n; i++){ arr[i] = sc.nextInt(); } int j = -1; int min = 0; boolean bool = false; for(int i = 0; i< n-1; i++){ if(arr[i] > arr[i+1]){ if(min < arr[i]){ if(min == 0){ min = arr[i]; j = i; } }else{ bool = true; break; } } } if(bool == true){ System.out.println("1"); }else{ if(j == -1){ System.out.println("4"); }if(j== 0){ System.out.println("1"); } else{ boolean check = true; for(int i= j*2; i< n; i+=j){ if(arr[i-j] > arr[i]){ check = false; break; } } if(check == true){ System.out.println("2"); }else{ System.out.println("1"); } } } } }