#include<bits/stdc++.h>
using namespace std;
int main()
{
bool t = false;
long long i = 1, j = 0, k = 0, l, o = -1, p = 0;
cin >> l;
long long n[l+20],m[l+20];
for (int f = 1; f <= l; f++)
{
cin >> n[f];
}
m[0] = 0;
for (int f = 0;;)
{
if (f == 1)
{
o++;
}
else if (f == l)
{
o++;
}
if (t == true)
{
t = true; f--; o++;
}
else if(t == false)
{
t = false; f++;
}
if (n[f] == m[p] + 1)
{
p++; m[p] = n[f];
}
if (m[l] == l) break;
}
if(o==-1)
{
cout << "0" << endl;
}
else
{
cout<< o << endl;
}
return 0;
}