#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;
template <class T>
bool chmax(T &map<int, int> MP;, const T &b) {
  if (map<int, int> MP; < b) {
    map<int, int> MP;
    = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &map<int, int> MP;, const T &b) {
  if (b < map<int, int> MP;) {
    map<int, int> 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() {
  ll x, y, n, m, h, k, w, max = -10000000, min = 2020202021, ans = 0, sum = 0;
  string s, t;
  cin >> n;
  VI map<int, int> MP;
  (n);
  for (int i = 0; i < n; i++) {
    cin >> map<int, int> MP;
    [i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (i + 1 == map<int, int> MP;[i]) {
      if (i + 2 == map<int, int> MP;[i + 1]) {
        ans++;
        i = i + 2;
      } else {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
