#include <iostream>                                                                                                                                                                                                                                                                
#include <algorithm>                                                                                                                                                                                                                                                               
#include <stdlib.h>                                                                                                                                                                                                                                                                
#include <vector>                                                                                                                                                                                                                                                                  
using namespace std;                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                   
typedef long long ll;                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                   
int main()                                                                                                                                                                                                                                                                         
{                                                                                                                                                                                                                                                                                  
    ll n;                                                                                                                                                                                                                                                                          
    cin >> n;                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                   
    vector<ll> p(n);                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                   
    for (int i=0; i<n; ++i)                                                                                                                                                                                                                                                        
        cin >> p[i];                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                   
    ll ans = 0;                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                   
    for (int i = 0; i<n; ++i) {                                                                                                                                                                                                                                                    
        if (p[i] == i+1) {                                                                                                                                                                                                                                                         
            ans++;                                                                                                                                                                                                                                                                 
            i++;                                                                                                                                                                                                                                                                   
        }                                                                                                                                                                                                                                                                          
    }                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                   
    cout << ans << endl;                                                                                                                                                                                                                                                           
}    

Measured memory_bytes: 1024