#include using namespace std; int n; vector a; int solve(); int main() { cin >> n; a.resize(n); for (auto &p : a) cin >> p; cout << solve() << endl; return 0; } int solve() { { // 0 bool ch = 1; for (int i = 1; i < n; ++i) if (a[i - 1] > a[i]) ch = 0; if (ch) return 0; } { // 1 int id = 0; for (int i = 0; i < n; ++i) if (a[id] > a[i]) id = i; if (id) { int last = a[id - 1], lid = id - 1; for (int i = id + 1; i < n; ++i) if (last <= a[i]) { lid = i; break; } bool ch = 1; if (id - 1 != lid) { for (int i = lid + 1; i < n; ++i) if (a[i - 1] > a[i]) ch = 0; } int len = (id - 1 == lid ? n : lid); for (int i = 1; i < len; ++i) if (a[(id + i - 1 + len) % len] > a[(id + i + len) % len]) ch = 0; if (ch) return 1; } } return 2; }