#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d[1005], t[1005];
  while (scanf("%d", &n) == 1) {
    int i, j;
    for (i = 0; i < n; ++i) {
      scanf("%d", &d[i]);
      t[i] = d[i];
    }
    sort(t, t + n);
    int ans = 0, index = 0;
    while (1) {
      ans = t[index];
      int flag = 0;
      for (i = 0; i < n; ++i) {
        if (t[index] == d[i]) {
          d[i] = 0;
        }
      }
      ++index;
      if (d[0] == 0 || d[n - 1] == 0) break;
      flag = 0;
      for (i = 1; i < n - 2; ++i) {
        if (d[i] == d[i + 1] && d[i] == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
