#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
int main(){
  int n;
  cin >> n;
  vector<int>p(n),ind(n,0);
  for(int i = 0; i < n; i++){
    cin >> p[i];
    
  }

  /*
  for(int i = 0; i < n ;i++)cout << ind[i] << " ";
  cout <<endl;
  */
  int ans = 99999999;
  for(int i = 0; i <= 3; i++){
    for(int i = 0; i < n; i++)ind[i] = p[i];
    int kind = i;
    ind[0] -= kind;
    for(int j = 0; j < n-1; j++){
      
      if(ind[j] < 0)ind[j] = 0;
      int temp = ind[j];
      ind[j+1] -= temp;
      kind += temp*2;
    }
    if(ind[n-1] < 0)ind[n-1] = 0;
    ans = min(ans,kind+ind[n-1]); 
  }
  /*
  for(int i = 0; i < n; i++)cout << p[i] << " ";
  cout << endl;
  */  
  cout << ans << endl;
}

