#include <bits/stdc++.h>
using namespace std;
long long keta(long long x) {
  for (long long i = 0; i < 30; i++) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
long long gcd(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
long long lcm(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[214514];
char t[214514];
char c[214514];
string second[214514];
long long a[214514], b[214514];
signed main() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (i + 1 == a[i]) {
      b[sum] = a[i];
      sum++;
    }
  }
  if (sum % 2 == 1) {
    b[sum + 1] = b[sum] + 1;
    sum++;
  }
  long long ans = 0;
  for (long long i = 0; i < sum; i += 2) {
    ans += b[i + 1] - b[i];
  }
  cout << ans << endl;
}
