#include <bits/stdc++.h>
using namespace std;
int solv() {
  int i, n;
  cin >> n;
  int a[n], b[n];
  bool bo[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    bo[i] = 1;
  }
  sort(b, b + n);
  int mn = min(a[0], a[n - 1]);
  int c, j, p = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (b[i] == a[j]) {
        bo[j] = 0;
        if ((j > 0 && bo[j - 1] == 0) || (j < n - 1 && bo[j + 1] == 0)) {
          c = b[i];
          p++;
          break;
        }
      }
      if (p) break;
    }
    if (p) break;
  }
  cout << min(c, mn);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int testcases = 1;
  while (testcases--) {
    solv();
  }
}
