#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void s() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  s();
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long time = 0;
  long long b = 0;
  if (a[0] == 0 || a[n - 1] == 0) {
    cout << 0 << "\n";
    return 0;
  }
  while (1) {
    long long t = INT_MAX;
    for (long long i = 0; i < n; i++)
      if (a[i] < t && a[i] != 0) t = a[i];
    for (long long i = 0; i < n; i++)
      if (a[i] != 0) a[i] -= t;
    time += t;
    if (a[0] == 0 || a[n - 1] == 0) break;
    for (long long i = 0; i < n - 1; i++)
      if (a[i] == 0 && a[i + 1] == 0) b++;
    if (b) break;
  }
  cout << time << "\n";
  return 0;
}
