#include <bits/stdc++.h>
using namespace std;
int arr[1000], n;
int valid(int day) {
  int flag = 0, i;
  if (day <= arr[0] && day <= arr[n - 1]) {
    for (i = 1; i < n; i++) {
      if (flag == 0) {
        if (day > arr[i]) flag = 1;
      } else {
        if (day <= arr[i])
          flag = 0;
        else
          break;
      }
    }
    if (i == n) return 1;
  }
  return 0;
}
int main() {
  cin >> n;
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > max) max = arr[i];
  }
  int i = 1;
  while (i <= max && valid(i)) i++;
  cout << i - 1 << endl;
}
