#include <bits/stdc++.h>
using namespace std;
void the_child_set(int sum, int limit) {
  int k = 0;
  int i = 0;
  int l1 = limit;
  map<int, int> map1;
  while (k != sum && l1 != 0) {
    int k1 = limit & 1;
    if (k1 == 1) {
      int check = pow(2, i);
      if (k + check <= sum) {
        map1[l1] = 1;
        k += check;
        l1--;
        limit = l1;
      } else if (k + check > sum) {
        l1--;
        limit = l1;
      }
      i = 0;
    } else {
      limit = limit >> 1;
      i++;
    }
  }
  if (k == sum) {
    int count = map1.size();
    cout << count << endl;
    auto it = map1.begin();
    while (it != map1.end()) {
      cout << it->first << " ";
      it++;
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int ans = 0;
  int check = 1;
  while (check == 1) {
    for (int i = 0; i < n; i++) {
      if (arr[i] == 0) continue;
      arr[i] = arr[i] - 1;
    }
    ans++;
    if (arr[0] == 0 || arr[n - 1] == 0) {
      break;
    }
    for (int i = 0; i < n - 1; i++) {
      if (arr[i] == 0 && arr[i + 1] == 0) {
        check = 0;
        break;
      }
    }
  }
  cout << ans << endl;
}
