#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=1010,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n;
int a[N];
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
int sum=0;
for(int tim=0;tim<n;tim++)
{
if(tim%2==0)
{
for(int i=1;i<=n;i++)if(sum>=a[i])
{
++sum;
a[i]=1e9;
}
}
else
{
for(int i=n;i>=1;i--)if(sum>=a[i])
{
++sum;
a[i]=1e9;
}
}
if(sum==n)
{
printf("%d\n",tim);
break;
}
}
}
return 0;
}
/*
【题意】
给你n([1,1000])个数a[],位于一个数轴上,我们每次可以选择向左或向右移动。
a[i]表示我们要打开第i号箱子需要先打开多少个箱子。
一开始我们在起点1,没有打开过箱子,问你至少要转弯多少次,才可以打开完所有的箱子(数据保证一定有解)
【类型】
贪心
【分析】
按照贪心策略,我们每次一定走到头再转弯,能拿的都拿。
最多转弯1000次,所以O(n^2)的暴力即可AC这道题。
*/