#include <bits/stdc++.h>
using namespace std;
int main() {
  int day = 0;
  int dari[1003] = {0};
  int n;
  bool ok = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &dari[i]);
  while (ok) {
    if (dari[0] <= 0) ok = 0;
    for (int i = 0; i < n - 1; i++)
      if (dari[i + 1] <= 0 && dari[i + 2] <= 0) ok = 0;
    for (int i = 0; i < n; i++) dari[i]--;
    day++;
  }
  printf("%d\n", day - 1);
  return 0;
}
