#include <bits/stdc++.h>
using namespace std;
long long int digits(long long int x) {
  long long int sum = 0;
  while (x) {
    sum++;
    x /= 10;
  }
  return sum;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  ;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << a[0];
    return 0;
  }
  for (long long int i = 0; i < n; i++) {
    long long int x = *min_element(a, a + n);
    for (long long int j = 0; j < n; j++) {
      if (x == a[j]) {
        a[j] = 1003;
      }
    }
    for (long long int j = 0; j < n - 1; j++) {
      if ((a[0] == 1003 || a[n - 1] == 1003) ||
          (j != 0 && j != n - 1 && a[j] == 1003 && a[j + 1] == 1003)) {
        cout << x;
        return 0;
      }
    }
  }
}
