#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> set;
  for (int i = 0; i < (int)(n); i++) {
    int p;
    cin >> p;
    p--;
    if (p == i) set.push_back(p);
  }
  int pre = -1;
  int ans = 0;
  sort(set.begin(), set.end());
  for (auto &s : set) {
    if (pre != -1) {
      ans += s - pre;
      pre = -1;
    } else {
      pre = s;
    }
  }
  if (set.size() % 2 != 0) ++ans;
  cout << ans << endl;
}
