#include #include using namespace std; typedef pair P; int main() { int n; cin >> n; int a[200005]; P p[200005]; for(int i = 0; i < n; i++){ cin >> a[i]; p[i] = P(a[i], i); } sort(p, p + n); int l = p[0].second; int i; for(i = 0; l + i < n; i++){ if(p[i].first != a[l + i]) break; } if(i == n){ cout << 0 << endl; return 0; } int r = l + i; l = -i; for(; i < r; i++){ if(p[i].first != a[l + i]){ cout << 2 << endl; return 0; } } for(; i < n; i++){ if(p[i].first != a[i]){ cout << 2 << endl; return 0; } } cout << 1 << endl; }