#include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n); multiset st; bool ok = true; for(int i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); if(i >= 1 && a[i] < a[i-1]) ok = false; } if(ok){ cout << 0 << endl; return 0; } int r = -1; for(int i = n-1; i >= 1; i--){ st.erase(st.find(a[i])); auto p = st.end(); p--; if(*p > a[i]){ r = i+1; break; } } int mn = 2e9; for(int i = 0; i < r; i++){ chmin(mn, a[i]); } int x = -1; for(int i = 0; i < r; i++){ if(a[i] == mn) { x = i; break; } } ok = true; for(int i = x; ;i = (i+1)%r){ if((i+1)%r == x) break; if(a[i] > a[(i+1)%r]) ok = false; } if(ok){ cout << 1 << endl; }else{ cout << 2 << endl; } }