#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int pos[100000 + 5];
int N,ans=0,correct=0;
set<int> S;//存储当前位置不对的
int main()
{
scanf("%d",&N);
for (int i = 0; i < N; i++) {
int num;
scanf("%d", &num);
pos[num] = i;
if (i == num) correct++;
else S.insert(i);
}
while (correct < N){
//换到正确位置
if (pos[0] == 0) {
//先跟随意一个位置交换
set<int>::iterator it=S.begin();
int num = *(it);
if (num == 0) num = *(++it);
pos[0] = pos[num];
pos[num] = 0;
correct--;
ans++;
}else{
int pZero = pos[0];
pos[0] = pos[pZero];
pos[pZero] = pZero;
S.erase(S.find(pZero));
ans++;
if (pos[0]==0) correct += 2;
else correct++;
}
}
printf("%d", ans);
return 0;
}
#include<algorithm>
#include<set>
using namespace std;
int pos[100000 + 5];
int N,ans=0,correct=0;
set<int> S;//存储当前位置不对的
int main()
{
scanf("%d",&N);
for (int i = 0; i < N; i++) {
int num;
scanf("%d", &num);
pos[num] = i;
if (i == num) correct++;
else S.insert(i);
}
while (correct < N){
//换到正确位置
if (pos[0] == 0) {
//先跟随意一个位置交换
set<int>::iterator it=S.begin();
int num = *(it);
if (num == 0) num = *(++it);
pos[0] = pos[num];
pos[num] = 0;
correct--;
ans++;
}else{
int pZero = pos[0];
pos[0] = pos[pZero];
pos[pZero] = pZero;
S.erase(S.find(pZero));
ans++;
if (pos[0]==0) correct += 2;
else correct++;
}
}
printf("%d", ans);
return 0;
}