#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef int64_t ll; typedef std::pair Pii; typedef std::pair Pll; typedef std::pair Pdd; #define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++) #define all(_l) _l.begin(), _l.end() #define rall(_l) _l.rbegin(), _l.rend() #define MM << " " << template using MaxHeap = std::priority_queue<_T>; template using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>; template inline bool chmax(_T &_l, const _T _b) { if (_l < _b) { _l = _b; return true; } return false; } template inline bool chmin(_T &_l, const _T _b) { if (_l > _b) { _l = _b; return true; } return false; } template void vdeb(const std::vector<_T> &bb) { for (unsigned int i = 0;i < bb.size();i++) { if (i == bb.size() - 1) std::cout << bb[i]; else std::cout << bb[i] << ' '; } std::cout << '\n'; } template void vdeb(const std::vector> &bb) { for (unsigned int i = 0;i < bb.size();i++) { std::cout << i << ' '; vdeb(bb[i]); } std::cout << '\n'; } using namespace std; bool is_sorted(vector &da) { rip(i, da.size()-1, 0) { if(da[i] > da[i+1]) return false; } return true; } bool is_cyc(vector &da) { int cnt = 0, vl; rip(i,da.size()-1,0) { if(da[i] > da[i+1]) { cnt++; vl = da[i+1]; if(cnt == 2) { return false; } } } return *min_element(all(da)) == vl; } int main() { int n; cin >> n; vector da(n); rip(i,n,0) cin >> da[i]; if(is_sorted(da)) { cout << 0 << endl; } else if(is_cyc(da)) { cout << 1 << endl; } else { cout << 2 << endl; } }