#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
#define int long long

signed main(){

	
	int n;
	cin>>n;

	int a[n];
	int b[n]={0};

	int count=0;
	int left=0;
	int right=n-1;
	int count_a=0;
	int count_b=0;

	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;

		if(i+1==tmp){
			a[i]=1;
		}else{
			a[i]=0;
		}
	}


	for(int i=0;i<n;i++){
		if(a[i]==1){
			left=i;
			break;
		}
	}


	for(int i=n;i>=0;i--){
		if(a[i]==1){
			right=i;
			break;
		}
	}

	// for(int i=0;i<n;i++){
	// 	cout<<a[i]<<" ";
	// }cout<<endl;

	for(int i=0;i<n;i++){
		if(a[i]==1)count_a++;
		if(a[i]==0)count_b++;
	}

	if(count_a==n){
		cout<<n-1<<endl;
		return 0;
	}

	if(count_b==n){
		cout<<0<<endl;
		return 0;
	}

	if(a[0]==1&&a[n-1]==1){
		cout<<n-1<<endl;
		return 0;
	}

	for(int i=0;i<n-1;i++){
		if(a[i]==1&&a[i+1]==1){
			count++;
			a[i]=0;
			a[i+1]=0;

			b[i+1]++;
		}
	}



	// cout<<"right="<<right<<endl;
	// cout<<"left="<<left<<endl;

	for(int i=left;i<right;i++){
		if(b[i]==1){
			count--;
		}
	}
	int add=right-left;
	count+=add;

	cout<<count<<endl;

}