#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n;
cin >> n;
int pos[100010];
int left = 0; //记录不在本位的个数
int begin; //记录0开始的位置
for(int i = 0; i < n; i++){
cin >> pos[i];
if(pos[i] != i){
left++;
}else{
pos[i] = -1;
}
if(pos[i] == 0){
begin = i;
}
}
// cout << left;
// cout << "begin:" << begin <<endl;
int num = 0;
int temp;
int k = 1;
while(left>0){
// cout << "left::::" << left << endl;
if(begin != 0){ //0不在0位
for(int i = 0; i < n; i++){
if(pos[i] == begin){
pos[begin] = -1;
pos[i] = 0;
begin = i;
num++;
//cout << i << " " << pos[i] << endl;
left--;
break;
}
}
}else{
while(k < n){
if(pos[k] != -1){
temp = pos[k];
pos[k] = pos[0];
pos[0] = temp;
begin = k;
//cout << "i::::" << i << endl;
num++;
break;
}
else{
k++;
}
}
}
int ii;
for(ii = 1; ii < n; ii++){
if(pos[ii] != -1){
break;
}
}
// cout << "ii:" << ii << endl;
if(ii == n){
cout << num;
break;
}
}
return 0;
}