#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i = 0, t[1005], x, z = 0;
  double a = 0;
  cin >> n;
  x = n;
  for (int b = 0; b < n; b++) {
    cin >> t[i];
    i++;
  }
  i = 0;
  n = x;
  x = 100;
  while (1) {
    if (i == (n)) {
      i = 0;
    }
    if (t[i] <= 0) {
      t[i] = 0;
      z = 0;
    } else {
      t[i] = t[i] - 1;
      z = 0;
    }
    if (i == 0) {
      a++;
    }
    if (t[i] == 0 && t[i - 1] == 0 || t[n - 1] == 0 || t[0] == 0) {
      break;
    }
    i++;
  }
  cout << a << endl;
  return 0;
}
