#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int count = 0;
  int days = 0;
  int min = INT_MAX;
  while (count < 2) {
    for (int i = 0; i < n; i++) {
      if (min > a[i] && a[i] > 0) min = a[i];
    }
    for (int i = 0; i < n; i++) {
      a[i] = a[i] - min;
      if (a[0] <= 0 || a[n - 1] <= 0) count = 2;
    }
    for (int i = 0; i < n - 1; i++) {
      if ((a[i] <= 0 && a[i + 1] <= 0)) {
        count = 2;
      }
    }
    days = days + min;
  }
  printf("%d", days);
  return 0;
}
