#include <bits/stdc++.h>
using namespace std;
int a[10000], n, i, j, p, q, ans;
bool possible() {
  if (a[1] < 0 || a[n] < 0) return false;
  for (int j = 1; j < n; j++)
    if (a[j] < 0 && a[j + 1] < 0) return false;
  return true;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  while (possible()) {
    ans++;
    for (i = 1; i <= n; i++) a[i]--;
  }
  ans--;
  cout << ans << endl;
}
