CSES - Shared codeLink to this code: https://cses.fi/paste/17d0c105267da8d76a177b/
#include<bits/stdc++.h>
using namespace std;

char nl = '\n';

void solve() {

    int n; cin >> n;
    int ans = 0;
    vector<int> a(n + 1);
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        a[x] = i;
    }
    for(int i = 2; i <= n; i++) {
        if(a[i] < a[i - 1]) ans++;
    }

    cout << ans + 1 << nl;
}

int main() {

    int t = 1;
    // cin >> t;
    while(t--) {

        solve();
    }

    return 0;
}