#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,ans=0,t=10000000;
  cin >> n;
  vector<int> a(n),b(n);
  for (int i=0;i<n;i++){
      cin >> a.at(i);
      b.at(i)=a.at(i);
  }
  for (int j=0;j<4;j++){
      for (int i=0;i<n;i++){
          a.at(i)=b.at(i);
      }
      ans=0;
  ans=ans+j;
  a.at(0)=a.at(0)-j;
  for (int i=0;i<n-1;i++){
      if (a.at(i)>0) {
          ans=ans+a.at(i)*2;
          a.at(i+1)-=a.at(i);
      }
  }
  if (a.at(n-1)>0) ans=ans+a.at(n-1);
  t=min(t,ans);
  }
  cout << t << endl;
}
