#include <iostream>
#include <assert.h>
#include <algorithm>
#include <memory.h>
#include <stdio.h>

using namespace std;

const int MAXN = 10000;

int n, a[2*MAXN+1], was[2*MAXN+1], cnt[MAXN+1];

int main(){
//   freopen("shelf.in","r",stdin);
//   freopen("shelf.out","w",stdout);

   scanf("%d",&n);
   
   assert(n>=1 && n<=MAXN);
   
   for (int i=1; i<=n; ++i) {
      scanf("%d",&a[i]);
      assert(a[i]>=1 && a[i]<=n && ++cnt[a[i]]==1);
   }
   
   int z=0, res=1<<30;
   for (int i=1; i<=n; ++i) a[i+n] = a[i];
   
   for (int st=0; st<n; ++st) {
      int* b = a+st, cur=n;
      ++z;
      for (int i=1; i<=n; ++i) if (was[i]<z){
         int j=i;
         while (b[j] != i) {
            j = b[j];
            was[j]=z;
         }
         --cur;
      }
      res = min(res,cur);
   }
   
   for (int i=1; i<=n; ++i) swap(a[i],a[2*n-i+1]);
   
   for (int st=0; st<n; ++st) {
      int* b = a+st, cur=n;
      ++z;
      for (int i=1; i<=n; ++i) if (was[i]<z){
         int j=i;
         while (b[j] != i) {
            j = b[j];
            was[j]=z;
         }
         --cur;
      }
      res = min(res,cur);
   }
   
   printf("%d",res);
   return 0;   
}
