#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
typedef vector<long long> VL;
typedef vector<VL> VLL;
template <class T, class U>
bool chmax(T &map<long long, long long> MP;, U b) {
  if (map<long long, long long> MP; <= b) {
    map<long long, long long> MP;
    = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &map<long long, long long> MP;, U b) {
  if (map<long long, long long> MP; > b) {
    map<long long, long long> MP;
    = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i < v.size() - 1 ? ", " : "");
  }
  os << "}";
  return os;
}
int main() {
  long long n, k, m, x = 0, y = 0, z = 0, h = 0, w = 0, ans = 0, sum = 1,
                     Max = -1, Min = 3e9 + 1;
  string s;
  bool ok = true;
  cin >> n;
  VL map<long long, long long> MP;
  (n);
  for (int i = 0; i < n; i++) {
    cin >> map<long long, long long> MP;
    [i];
    if (i + 1 == map<long long, long long> MP;[i]) {
      ans++;
      if (i > 0 && i == map<long long, long long> MP;[i - 1]) {
        w++;
      }
    }
  }
  cout << (ans - ((w + 1) / 2)) << "\n";
  return 0;
}
