#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#else
#define dbg(exp) /* nop; */
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

int main() {
    int n;
    cin >> n;

    vector<int> arr(n);
    for (int& e : arr)
        cin >> e;

    int l = -1;
    int ans = 0;
    for (int i = 0; i < n; i ++) {
        if (arr[i] == i + 1) {
            if (l == -1) {
                l = i;
            } else {
                ans += (i - l);
                l = -1;
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

