#include <iostream>
using namespace std;
const int MAX_SIZE = 1000;
int main() {
int n, v[MAX_SIZE + 1];
cin >> n;
int zone = 0;
for (int i =1; i <= n; ++i) {
cin >> v[i];
}
int destination = 1;
for (int i = 1; i <= n; ++i) {
int flag = 0;
for (int j = destination; j <= destination; ++j) {
// cout << i << " ";
if(i != v[j] && v[j] != 0 ) {
flag = 1;
destination = v[j];
/// v[j] = 0;
//cout << destination << " ";
}
if(flag == 0 && i == v[j]) {
// cout << v[j]<< " ";
++zone;
// v[i] = 0;
// v[j] = 0;
j = n;
}
flag = 0;
}
}
cout << zone ;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFICA9IDEwMDA7CmludCBtYWluKCkgewoJaW50IG4sIHZbTUFYX1NJWkUgKyAxXTsKCWNpbiA+PiBuOwoJaW50IHpvbmUgPSAwOwoKCWZvciAoaW50IGkgPTE7IGkgPD0gbjsgKytpKSB7CgkJY2luID4+IHZbaV07Cgl9CgkJaW50IGRlc3RpbmF0aW9uID0gMTsKCWZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewoJCWludCBmbGFnID0gMDsKCQkKCWZvciAoaW50IGogPSBkZXN0aW5hdGlvbjsgaiA8PSBkZXN0aW5hdGlvbjsgKytqKSB7CgkvLwljb3V0IDw8IGkgPDwgIiAiOwoJCWlmKGkgIT0gdltqXSAmJiB2W2pdICE9IDAgKSB7CgkJZmxhZyA9IDE7CgkJZGVzdGluYXRpb24gPSB2W2pdOwoJLy8vCXZbal0gPSAwOwoJCS8vY291dCA8PCBkZXN0aW5hdGlvbiA8PCAiICI7CgkJfQoJCWlmKGZsYWcgPT0gMCAmJiBpID09IHZbal0pIHsKCQkvLwljb3V0IDw8IHZbal08PCAiICI7CgkJCSsrem9uZTsKCQkvLwl2W2ldID0gMDsKCQkvLwl2W2pdID0gMDsKCQlqID0gbjsKCQkJCgkJfQoJZmxhZyA9IDA7CgkJfQkKCX0KCWNvdXQgPDwgem9uZSA7CglyZXR1cm4gMDsKfQ==