#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T begin, T end) {
  for (T i = begin; i != end; ++i) cout << *i << " ";
  cout << endl;
}
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int main() {
  int N;
  while (cin >> N && N) {
    vector<pair<int, int> > event(N);
    for (int i = (0); i < (int)N; ++i) {
      int A;
      cin >> A;
      event[i] = pair<int, int>(A, i);
    }
    sort(event.begin(), event.end());
    bool breaked[1000] = {};
    for (int t = (0); t < (int)N; ++t) {
      breaked[event[t].second] = true;
      bool ok = true;
      if (breaked[0] || breaked[N - 1]) ok = false;
      for (int i = 0; i < N - 1; i++) {
        if (breaked[i] && breaked[i + 1]) ok = false;
      }
      if (!ok) {
        cout << event[t].first << endl;
        break;
      }
    }
  }
  return 0;
}
