#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t a[n + 2], max1 = 0;
  for (int64_t i = 1; i <= n; i++) {
    cin >> a[i];
    max1 = max(a[i], max1);
  }
  a[0] = max1 + 1;
  a[n + 1] = max1 + 1;
  max1 = min(a[n], a[1]);
  for (int64_t i = 1; i <= n; i++) {
    if (a[i] < max1 && (a[i] >= a[i - 1] || a[i] >= a[i + 1])) {
      max1 = a[i];
    }
  }
  cout << max1;
}
