#include <iostream>
#include <bits/stdc++.h>
#define fre freopen("input.txt","r",stdin) , freopen("output.txt","w",stdout) ;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
const int N = 1e5 + 5;
using namespace std;
void solve() {
int n;cin>>n;
vector<int>vec(n);
for (int i = n-1; i >= 0; --i) {
cin>>vec[i];
}
int start=vec[0];
int end = vec[n-1];
int count=0;
bool valid=true;
while(vec[0]!=0){
valid=true;
for (int j = 0; j < n;) {
if(vec[j]>0){
vec[j]--;
if(vec[j+1]!=0){j++;}
else{
j+=2;
}
}else{
valid=false;
break;
}
}
if(valid)count++;
}
cout<<min(count,min(start,end))<<"\n";
}
int main() {
IO
int t;
// cin >> t;
t = 1;
while (t--) {
solve();
}
}
/*
// you can use includes, for example:
#include <bits/stdc++.h>
using namespace std;
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool arr[15];
bool isCool(int num){
string s = to_string(num);
// pali
int size = s.size();
for(int i =0 ; i <=size/2; i++){
if(s[i]!=s[size-i-1]){
return false;
}
}
map<char,int>mp;
for(int i =0 ; i < size; i++){
if(mp[s[i]]!=0){
return false;
}else{
mp[s[i]]++;
}
}
return true;
}
int total=0;
int mx=-1;
int magic(int sum ,int numOfCoolOnesr ,vector<int> vec ){
if(sum==total){
return numOfCoolOnesr;
}
int cool =numOfCoolOnesr;
for(int i = 0 ; i < vec.size() ; i++){
if(!arr[0]){
arr[0]=true;
if(isCool(sum+vec[i])){
cool++;
}
mx=max(mx,magic(sum+vec[i],cool,vec));
arr[0]=false;
}
}
}
int solution(int X, vector<int> &B) {
// Implement your solution here
for(int i = 0 ; i < B.size() ; i++){
total+= B[i];
}
magic(X,0,B);
return mx;
}
*/
1717C - Madoka and Formal Statement | 420A - Start Up |
1031A - Golden Plate | 1559C - Mocha and Hiking |
427B - Prison Transfer | 330A - Cakeminator |
426A - Sereja and Mugs | 363A - Soroban |
1585C - Minimize Distance | 1506E - Restoring the Permutation |
1539A - Contest Start | 363D - Renting Bikes |
1198D - Rectangle Painting 1 | 1023B - Pair of Toys |
1725A - Accumulation of Dominoes | 1675E - Replace With the Previous Minimize |
839A - Arya and Bran | 16B - Burglar and Matches |
1625B - Elementary Particles | 1725G - Garage |
1725B - Basketball Together | 735A - Ostap and Grasshopper |
1183B - Equalize Prices | 1481A - Space Navigation |
1437B - Reverse Binary Strings | 1362B - Johnny and His Hobbies |
1299A - Anu Has a Function | 1111A - Superhero Transformation |
954A - Diagonal Walking | 39F - Pacifist frogs |