using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Pi = Sarray();
            var start = 0;
            for (var i = 0; i < Pi.Length; ++i)
            {
                if (Pi[i] != i + 1)
                {
                    start = i;
                    break;
                }
            }
            var ans = 0L;
            var cnt = 0L;
            for (var i = start; i <start+Pi.Length; ++i)
            {
                var pos = i % Pi.Length;
                if (Pi[pos] == pos + 1)
                {
                    ++cnt;
                }
                else
                {
                    ans += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
            ans += (cnt + 1) / 2;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}