#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 300010;
int n , arr[N] , cur[N];
vector< pair< int , int > > v;
int main(){
scanf("%d",&n);
int last = 0;
for(int i = 0 ;i < n - 1;i++){
scanf("%d",&arr[i]);
cur[i] += arr[i];
cur[i + 1] += arr[i];
if(arr[i] == 0){
v.push_back(make_pair(last , i));
last = i + 1;
}
}
v.push_back(make_pair(last , n - 1));
int ans = 0;
for(int a , b , i = 0 ;i < (int)v.size();i++){
a = b = 0;
for(int j = v[i].first ;j <= v[i].second;j++){
if(cur[j] != 0)
b = 1;
if(cur[j] & 1){
a++;
}
}
ans += max(b , a / 2);
}
cout << max(0 , ans - 1) << endl;
return 0;
}
Copy