#include <iostream>
#include <cstdlib>
using namespace std;

#define MAXN 101

int a[MAXN];

int main(){
	int n,ans=0,subtract=0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int newstart, newend;
	// remove zeroes at the front
	for (int i = 0; i < n; i++){
		if (a[i] == 1){
			newstart = i;
			break;
		}
	}
	// remove zeroes at the back
	for (int i = n-1; i >= 0; i--){
		if (a[i] == 1){
			newend = i;
			break;
		}
	}
	for (int i = newstart; i <= newend; i++){
		// find all number of ones
		// find all number of zeros neighboured by ones.
		ans += a[i]==1;
		ans += a[i]==0&&a[i+1]==1&&a[i-1]!=0;
		/*
		if (a[i] == 1) ++ans;
		else if (a[i] == 0 && a[i+1] == 1 && a[i-1] != 0) ++ans;  */
	}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
    int a;
    cin >> a;
    int b[a];
    for(int i=0;i<a;i++)
    {
        cin >> b[i];
    }
    int c=0 , d=0 , e=0;
    for(int i=0;i<a;i++)
    {
        if(b[i]==1&&e!=1)
        {
            e=1;
            d++;
        }
        else{
            if(b[i]==1)
            {
                if(c<2)
                {
                    d+=c;
                    c=0;
                }
                else{
                    c=0;
                }
                d++;
            }
            else{
                    if(e!=0)
                    {
                c++;
                    }
            }
        }
    }
    cout << d << endl;
}

#include<iostream>
using namespace std;
int main()
{
	int n,m[101],f=0;
	cin>>n;
	for (int i=0;i<n;i++)
	cin>>m[i];
	for (int i=0;i<n;i++)
	{
	if(m[i]==0&&m[i-1]==1&&m[i+1]==1)
		f++;
	if(m[i]==1)
		f++;
	}
	cout<<f;
	return 0;
}

#include<cstdio>
int a[150];
int main()
{
	int n,sum,flag,flag1;
	while(~scanf("%d",&n))
	{
		sum=0,flag=1,flag1=1;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i]==1) sum++;
		}
		for(int i=0;i<n;i++)
		{
			if(a[i]==1&&a[i+1]==0&&a[i+2]==1)
			{
				sum++;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int n;
    int *a;
    cin>>n;
    a=new int [n];
    for(int i=0;i<n;i++)cin>>a[i];

    int i=0,j=n-1,c=0,d;
    while(a[i]==0 ){  i++;if(i>=n)break;}
    while(a[j]==0 ){ j--; if(j<=0)break;}
    d=j-i+1;
    //cout<<i<<" "<<j<<endl;
    //cout<<d<<endl;
    for(;i<j;i++)
    {
        if(a[i]==0)
        {c=0;
            while(a[i++]==0&&i<n)
            c++;
            if(c>1)d=d-c;
            i--;

        }
    }
    if(d<=0)cout<<"0\n";
    else cout<<d<<endl;

}

#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
using namespace std;
typedef long long int ll;
vector<int>v;
#define PI           3.14159265358979323846

int main()
{
    int n,a,b,ans=0,len,i,cnt;

    cin>>n;
    int arr[n+5];

    for(i=0;i<n;i++)
    {
         cin>>arr[i];
    }
    cnt = 2;
     for(i=0;i<n;i++)
     {
           if(arr[i]==1)
           {
              ans++;

               if(cnt<2)
               ans+=cnt;
               //cout<<ans<<" "<<cnt<<" "<<i<<endl;
               cnt = 0;
           }
           else
           {

                cnt++;
           }
     }
     cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define done cin.tie(0);std::ios::sync_with_stdio(false);
#define forit(i, a) for ( __typeof( (a).begin() ) i = (a).begin(); i != (a).end(); i++ )
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define all(c) c.begin(), c.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(j,i,n) for(int j=i+1;j<n;j++)
//ll gcd (ll x,ll y){if(y==0)return x;return gcd(y,x%y);}
//ll lcm(ll a,ll b){return a/gcd(a,b) * b;}
//bool cmp(pair<int,int>x,pair<int,int>y)
//{if (x.first==y.first) return x.second<y.second;return x.first>y.first;}
int main()
{
    done
    int x;
    cin>>x;
    vector<int>vec(x);
    int st=0;
    rep(i,x)
    {
        cin>>vec[i];
    }
    rep(i,x)
    {
        if(vec[i]){st=i+1;break;}
    }
    if(!st){cout<<0<<endl;return 0;}
    st--;
    int p=0,c=0,n=0;
    for(int i=st;i<vec.size();i++)
    {
        if(vec[i])
        {
            c++;
            n=(p==1?1:0);
            c+=n;
            p=0;
        }
        else
            p++;
    }
    cout<<c<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define INF 10000000000000
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"
#define BS binary_search
#define N 100005

void solve()
{
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==1)
			ans++;
	    if(a[i]==0){
			if(i!=n-1 && a[i-1]==1 && a[i+1]==1 && i!=0)
				ans++;
		}
	}
	cout<<ans;

}

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
   	int tc=1;
   	//cin>>tc;
   	while(tc--)
   		solve();
}

#include <iostream>
using namespace std;
int a[102];
void main()
{
	int n, count = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 0 && (a[i - 1] == 0 || a[i + 1] == 0))
			continue;
		count++;
	}
	cout << count << endl;
}

#include <iostream>
#define _at_sch (0)
#define _at_home (1)
#define _ready_home (2)

using namespace std;

int main() {
	int N;
	cin >> N;
	int a[1000];
	int num_class = 0;
	for (int i = 0; i < N; ++ i) {
		//++ num_class;
		cin >> a[i];
		if (a[i])
			++ num_class;
	}

	int i = 0, ans = 0;
	//while (!a[i])
		//++ i;
	int states = _at_home;
	while (i < N && num_class) {
		switch (states) {
			case _at_sch:
				if (!a[i])
					states = _ready_home;
				else {
					-- num_class;
					++ ans;
				}
				break;
			case _at_home:
				if (a[i]) {
					-- num_class;
					states = _at_sch;
					++ ans;
				}
				break;
			case _ready_home:
				if (a[i]) {
					-- num_class;
					states = _at_sch;
					ans += 2;
				}
				else {
					states = _at_home;
				}
				break;
			default: break;
		}
		++ i;
	}
	cout <<ans << endl;

	return 0;
}

#include <iostream>

using namespace std;

int main(){
    int n;
    int a[105];
    cin >> n;
    for(int i = 0; i < n; i++){
          cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
          if(a[i] == 0 && !ans) continue;
          if((a[i] == 0 && a[i + 1] == 0) || (a[i] == 0 && a[i - 1] == 0) || (a[i] == 0 && i == n - 1))continue;
          ans++;
    }
    cout << ans;
    return 0;
}

#include <iostream>

using namespace std;
int a[110];
int main()
{
    //cout << "Hello world!" << endl;
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
     cin>>a[i];
    }
    int s=0;
    for(int i=0;i<n;i++)
    if(a[i])
        s++;
    else
    {
        if(a[i-1]&&a[i+1])
            s++;
    }
        cout<<s<<endl;
    return 0;
}

#include <iostream>
using namespace std;
int n, a[10001];
int ans;
int main()
{
    cin >> n;
    for (register int i = 1;i <= n;i ++) cin >> a[i];
    ans = n;
    for (int i = 1;i <= n;++ i)
    {
        if(!a[i])
        {
            if(!a[i - 1] || !a[i + 1])
            {
                ans --;
            }
        }
    }
    cout << ans;
}

//2016-04-03 08:12:19.328000
#include <stdio.h>
#include <algorithm>

using namespace std;

int a[110];

int main (){
	int n,i,st=-1,ed=-1;
	scanf("%d",&n);
	st=n;
	for(i=0; i<n; i++){
		scanf("%d",a+i);
		if(a[i]) {
			ed=i;
			st=min(st,i);
		}
	}
	int tot=0;
	for(i=st; i<=ed; i++){
		if(a[i] || a[i]==0 && a[i-1] && a[i+1]) tot++;
	}
	printf("%d\n",tot);
	return 0;
}

//2016-04-03 08:16:10.501000
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <string.h>

using namespace std;

#define rep(i, a, b) for (int i=(a); i<(b); i++)
#define rrep(i, a, b) for (int i=(a); i>=(b); i--)
#define NN 110

int a[NN];

int main() {

	int N, ct;
	scanf("%d", &N);
	rep(i, 0, N) scanf("%d", a+i);
	ct=0;
	rep(i, 0, N) {
		if (a[i]==1) continue;
		if (i==0 || i==N-1) ct++;
		else {
			if (i && a[i-1]==0) ct++;
			else if (i<N-1 && a[i+1]==0) ct++;
		}
	}
	printf("%d\n", N-ct);

	return 0;
}

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

typedef long long int ll ;

int main()
{
    int n ;
    scanf("%d",&n);
    int in[n] ;
    for(int i=0 ; i<n ; i++) {
        scanf("%d",&in[i]) ;
    }
    int j=0 ;
    while(j<n && in[j]==0) {
        j++ ;
    }
    int pos=-1 ;
    for(int i=n-1 ; i>=0 ; i--) {
        if(in[i]==1) {
            pos=i ;
            break ;
        }
    }
    if(pos==-1) {
        printf("0\n") ;
        return 0 ;
    }
    int coun=0 ;
    for(int i=j ; i<=pos ; i++) {
        if(in[i]==1) {
            coun++ ;
        }
        else {
            int tempCoun=0 ;
            int k=i ;
            while(k<=pos && in[k]==0) {
                tempCoun++ ;
                k++ ;
            }
            if(tempCoun>=2) {
                i=k-1 ;
            }
            else {
                coun++ ;
            }
        }
    }
    printf("%d\n",coun) ;
    return 0 ;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
cin>>n;
int a[101];
fill(a,a+101,0);
int cont=0,t=0,temp;
for(int i=0;i<n;i++)
{
cin>>temp;
if(temp==0&&t==0)
    continue;
else
{
t=1;
    a[cont++]=temp;
}}
int cnt=0;
for(int i=0;i<cont;i++)
    if(a[i]==0&&a[i+1]==0)
    {
        while(a[i]!=1&&i<cont)
            i++;
        if(a[i]==1)
        cnt++;
    }
else
{
    cnt++;
}

cout<<cnt<<endl;
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define ll long long
#define ull unsigned long long
#define MAX_INT 4294967296
#define INF 1000000007
#define EPS 0.000000001
#define PI 3.14159265359
#define RAD 57.2957795
#define undef ""

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	int j = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}
	for (j; j < n; ++j)
		if (v[j] == 1)
			break;
	int ans = 0;
	for (j; j < n; ++j)
	{
		if (v[j] == 1)
			++ans;
		if ((v[j] == 0 && j + 1 >= n) || (v[j] == 0 && j + 1 < n && v[j + 1] == 0))
		{
			while (j < n && v[j] == 0) ++j;
			--j;
		}
		else if (v[j] == 0) ++ans;

	}
	cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[105];
  int b,c,d=0;
  cin>>b;
  for(int i=0;i<b;i++){
  	cin>>a[i];
  }
  for(int i=0;i<b;i++)
    if(a[i]=='1') d++;
  for(int i=1;i<b-1;i++){
  	if(a[i]=='0'&&a[i-1]=='1'&&a[i+1]=='1') d++;
  }
  cout<<d;
  return 0;
}

#include <stdio.h>
#include <string>

using namespace std;
int main()
{

    int n,ans=0,a,s=0;
    bool b=0,k=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==0 && !k)
            continue;
        k=1;
        if(a)
            if(b)
            {
                ans+=2;
                b=0;
                s=0;
            }
            else
            {
                ++ans;
                s=0;
            }
        else
            if(s==0)
            {
                ++s;
                b=1;
            }
            else
                b=0;
    }
    printf("%d",ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,a[110],ans=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	if(a[i]==1)
    		ans++;
	}
    for(int i=2;i<n;++i)
        if(a[i]==0&&a[i-1]==1&&a[i+1]==1)
        	ans++;
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0,e=0,d=0,f=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]==1||a[i]==0&&a[i+1]==1&&a[i-1]==1){continue;}
        else cnt++;
    }
    if(n-cnt<0)cout<<"0";
    else cout<<n-cnt;
}

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

int n, x, tmp, kq;
bool check;
vector <int> vc;

int main() {
    //freopen("tmp.inp", "r", stdin);
    //freopen("tmp.out", "w", stdout);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (x == 1) check = true;
        if (check) vc.push_back(x);
    }

    n = vc.size();
    for (int i = 0; i < n; ++i) {
        if (vc[i] == 0) ++tmp;
        else {
            ++kq;
            if (tmp == 1) ++kq;
            tmp = 0;
        }
    }

    cout << kq;
    return 0;
}

    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int n,a[101],ans,ok,l;

    int main()
    {
    scanf("%d",&n);
    ok=n;
    for(int i=0;i<n;i++){scanf("%d",&a[i]);
    if(ok==n&&a[i]){ok=i;}
    if(a[i]){l=i;}
    }
    for(int i=ok;i<=l;i++){
        if(!a[i]&&(!a[i+1]||!a[i-1])){continue;}
            ans++;
    }
    printf("%d\n",ans);
        return 0;
    }

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long int
#define pb          push_back
#define endl        '\n'
#define piil         pair<ll ,ll >
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(a,b,i)  for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v;
    rep(0,n,i)
    {
       int x;
       cin >> x;
       v.pb(x);
    }
    int m=find(all(v),1)-v.begin();
    reverse(all(v));
    int k=find(all(v),1)-v.begin();
    reverse(all(v));

    int c=0;
    for(int i=m;i<n-k;i++)
    {
        if(v[i]==0 && v[i+1]==0)
         {
             while(v[i]!=1)
             i++;
         }
        c++;
    }

    cout << c;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main ()
{
    int n;
    cin >> n;
    int* a;
    a = new int [n];
    for (int i=0; i<n; ++i)
    {cin >> a[i];}
    int x=a[0];
    int y=a[1];
    int f=1;
    int s=0;
    for (int i=0; i<n-1; ++i)
    {
        if (f==0)
        {
            if (x==1)
            {
                ++s;
            }
            else
            {
                if (y==1)
                {
                    ++s;
                }
                else
                {
                    f=1;
                }
            }
        }
        else
        {
            if(x==1)
            {   ++s;
                f=0;
            }
        }
        x=y;
        y=a[i+2];
    }
    if (a[n-1]==1) ++s;
    delete[] a;
    cout << s;
}

/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\       ||  ||     \\||
||  \\   \\_____ //  ||      \ |

*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>

#define ll              long long
#define endl            '\n'
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define f               first
#define s               second
#define sz(a)           (int)a.size()
#define sf(a)           scanf("%d",&a)
#define sc(a)           scanf("%lld",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define scc(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sccc(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

using namespace std;

//vector< pair <int,int> > v;
/*
bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
*/

void solve()
{
    int n, i, cnt;
    cin >> n;
    int a[n];
    for(i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(i = 1; i < n - 1; ++i) {
        if(a[i + 1] == 1 && a[i - 1] == 1) a[i] = 1;
    }
    cnt = 0;
    for(i = 0 ; i < n; ++i)
        if(a[i] == 1) ++cnt;
    cout << cnt;
    return;
}

int main()
{
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
#define pb push_back

const int tope = 100 + 5;

int n, ans = 0;
vi vent;
int a[tope];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int primero = -1, ultimo = -1, aux;
    for(int i=0; i<n; i++){
        cin >> aux;
        if(aux != 0 && primero == -1){
            primero = i;
        }
        if(aux == 1){
            ans++;
            ultimo = i;
        }else if(aux == 0 && primero != -1){
            vent.pb(i);
        }
    }
    if(primero == - 1){
        cout << ans << "\n"; return 0;
    }
    if(!vent.empty()){
        for(int i = 0; i<vent.size()-1; i++){
            if(vent[i]>ultimo) break;
            int j = i+1;
            while(vent[j] - vent[i] == j - i){
                j++;
            }
            j--;
            if(i == j){
                ans++;
            }
            i = j;
        }
        int cant = vent.size();
        if(vent[cant-1] < ultimo){
            if(cant > 1){
                if(vent[cant-1] - vent[cant - 2] > 1){
                    ans++;
                }
            }else{
                ans++;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

/*Чем уникально слово «Аллах - الله»?

Само слово «Аллах» в арабском языке имеет уникальную структуру: ни одно другое слово в арабском или другом языке не может сохранить своё основное значение при удалении одной из четырёх букв.

Если мы разберем слово «Аллах» на отдельные буквы, то получим следующие четыре буквы:

ا ل ل ه -  الله
После удаления первой буквы,  остаются буквы:
ل ل ه - لله
Убрав вторую букву, получаем:
ل ه -  له
А после удаления третьей буквы, получается:
ه -  هو

Таким образом, несмотря на исключение одной буквы за раз, монотеистическое значение слова сохраняется, потому что четыре группы букв ل ه له , ل ل ه لله  , ا ل ل ه ,الله и ه هو синонимы и эквивалентные слову الله.

Кроме того, обратите внимание, что в Коране слово الله повторилось 2811 раз, слово لله повторилось 116 раз, а слово له – 380 раз.
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a, z = 0;
	cin>>a;
	ll ar[a];
	for(ll i = 0; i<a; i++)
	{
		cin>>ar[i];
	}
	for(ll i = 0; i<a; i++)
	{
		if(ar[i] == 1 || ar[i+1] == 1 && ar[i-1] == 1)
		{
			z++;
		}
	}
	cout<<z<<endl;
	return 0;
}

#include<stdio.h>
int main() {
	int n;
	int a[105];
	scanf("%d", &n);
	for (int i = 0;i < n;i++) scanf("%d", &a[i]);

	int first = 0, last = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			first = i; break;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == 1) {
			last = i; break;
		}
	}
	int consezero = 0;
	int ans = last - first + 1;
	if (first == last && a[first] == 0) ans = 0;
	else {
	for (int i = first; i <= last; i++) {
		if (i > 0 && a[i] == 0 && a[i - 1] == 0) {
			if (consezero >= 2) consezero++;
			else consezero = 2;
		}
		if (a[i] == 1) {
			ans -= consezero;
			consezero = 0;
		}
	}
}
	printf("%d", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
struct threeElements{
int _1st,_2nd,_3rd;
};
int n;
int dp[10000001][2];
int solve(int k,int now)
{
    if(k==n&&now==0)
        return 1;
    if(k>=n) return 0;
    if(dp[k][now]!=-1) return dp[k][now];
    ll ans=0;
    for(int i=0;i<4;i++)
    {
        if(now!=i)
        (ans+=solve(k+1,i));
    }
    return dp[k][now]=ans%mod;
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   cin>>n;
   int idx;
   bool a[100009];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       if(a[i]) idx=i;
   }
   int ans=0;
   for(int i=0;i<=idx;i++)
   {
       if(a[i])ans++;
       else
       {
           if(a[i+1]&&a[i-1]&&ans) ans++;
       }
   }
   cout<<ans;
}

#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
using namespace std;
int main (){
int n,k=0,p=-1,m=-1,l=0,b=0;
cin>>n;
int a [n];
for (int i = 0; i <n; ++i) {
cin>>a [i];
if(a [i]==1&&k==0){
k=1;
p=i;
}
if (a [i]==1&&k==1){
m=i;
}
}
for (int i=p;i <=m;i++){
if (a [i]==1){
if (b==1){
l++;
}
l++;
b=0;
}
else {
b++;
}
}
if (p==-1&&m==-1){
cout <<"0";
}
else {
cout <<l;
}
return 0;
}

#include<bits/stdc++.h>

#define lld long long int
#define FOR(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FOR(i,1,n+1)
#define all(x) x.begin(),x.end()
#define LET(x,a) __typeof(a) x(a)
#define IFOR(i,a,b) for(LET(i,a);i!=(b);++i)
#define EACH(it,v) IFOR(it,v.begin(),v.end())
#define PB push_back
#define sz size()
#define pii pair<int, int>
#define pll pair <lld ,lld>
#define MP make_pair
#define fill(x,v) memset(x,v,sizeof(x))
#define scan(v,n) vector<int> v(n);rep(i,n)cin>>v[i];
#define vi vector<int>
#define MOD 1e9 + 7
#define F first
#define S second

using namespace std;

lld modpow(lld a,lld n,lld temp){lld res=1,y=a;while(n>0){if(n&1)res=(res*y)%temp;y=(y*y)%temp;n/=2;}return res%temp;}
int main()
{
	int N;
	cin >> N;
	bool flag = true;
	vector <int> a(N);
	FOR(i, 0, N)
		cin >> a[i];
	int ans = 0, i = 0;
	while(i < N)
	{
		if(a[i] == 1)
			break;
		i++;
	}
	FOR(j,i,N)
	{
		if(a[j] == 1)ans++;
		else if(j < 1) continue;
		else if(a[j-1] == 1 and j >= 1 and j != N - 1)ans++;
		else if(j < 2) continue;
		else if(a[j-1] == 0 and a[j-2] == 1)ans--;

	}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>

#define lld long long int
#define FOR(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FOR(i,1,n+1)
#define all(x) x.begin(),x.end()
#define LET(x,a) __typeof(a) x(a)
#define IFOR(i,a,b) for(LET(i,a);i!=(b);++i)
#define EACH(it,v) IFOR(it,v.begin(),v.end())
#define PB push_back
#define sz size()
#define pii pair<int, int>
#define pll pair <lld ,lld>
#define MP make_pair
#define fill(x,v) memset(x,v,sizeof(x))
#define scan(v,n) vector<int> v(n);rep(i,n)cin>>v[i];
#define vi vector<int>
#define MOD 1e9 + 7
#define F first
#define S second

using namespace std;

lld modpow(lld a,lld n,lld temp){lld res=1,y=a;while(n>0){if(n&1)res=(res*y)%temp;y=(y*y)%temp;n/=2;}return res%temp;}
int main()
{
    int N;
    cin >> N;
    int prev = -1;
    int ans = 0;vector <int> arr(N);
    FOR(i, 0, N)
        cin >> arr[i];

    int ind = 0;
    bool done = false;
    FOR(i, 0, N)
    {
        if(arr[i] == 0)
            ans++;
        else
        {
            ind = i;
            done = true;
            break;
        }
    }
    bool flag = true;

    if(done == true)
    {
        FOR(i, ind, N - 1)
        {
            if(arr[i] == 0 && arr[i + 1] == 0)
            {
                ans += 1;
                flag = false;
            }
            if(arr[i] == 0 && arr[i+1] == 1 && flag == false)
            {
                flag = true;
                ans += 1;
            }

        }
    }
    if(arr[N - 1] == 0 && done == true)
        ans++;

    cout << N - ans << endl;
    return 0;
}

#include <cstdio>

int main(){
int n,a[100],r= 0;
scanf("%d",&n);
for(int i =0 ; i < n; i++) scanf("%d",&a[i]);
for(int i = 0 ; i < n; i++){
if(a[i]){ r++; continue; }
if( i > 0 && a[i-1] && i+1 < n && a[i+1]) r++;
}
printf("%d",r);
return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
    fast
    ll i,j,n,m,k,x,ans=0;
    string s,t;
    cin>>n;
    ll a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==1)
            ans++;
    }
    for(i=1; i<n-1; i++)
    {
        if(a[i]==0)
        {
            if(a[i-1]==1&&a[i+1]==1)
                ans++;
        }
    }

cout<<ans<<endl;

// cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
return 0;
}

#include <bits/stdc++.h>

// settings
    #define FILE "bridges"
    #define USE_FREOPEN 0
    #define USE_LONG 0
    #define USE_IOSOPT 0
    #define INTERACT 0

// system
    #if USE_LONG
        typedef long long ll;
    #else
        typedef int ll;
    #endif
    #if USE_LONG
        typedef unsigned long long ull;
    #else
        typedef unsigned int ull;
    #endif
    #if INTERACT
        #define eol endl
    #else
        #define eol '\n'
    #endif
    #define pb push_back
    #define mp make_pair
    #define p(a, b) pair < a, b >
    #define sq(x) (x * x)
    #define f first
    #define s second
    #define rm erase
    #define ins insert
    #define rev(a) reverse(a.begin(), a.end())
    #define rs resize
    #define sz size
    #define M2 (ll)1e2
    #define M3 (ll)1e3
    #define M4 (ll)1e4
    #define M5 (ll)1e5
    #define M6 (ll)1e6
    #define M7 (ll)1e7
    #define M8 (ll)1e8
    #define M9 (ll)1e9
    #define MOD 16714589

using namespace std;

int main()
{
    // ios
        #if USE_IOSOPT
            ios_base::sync_with_stdio(false);
            cin.tie(0);
        #endif
        #if USE_FREOPEN
            freopen(FILE".in", "r", stdin);
            freopen(FILE".out", "w", stdout);
        #endif
    ll n;
    cin >> n;
    vector < ll > a;
    for(int i = 0; i < n; i++)
    {
        ll d;
        cin >> d;
        a.pb(d);
    }
    if(n == 1)
    {
        cout << a[0];
        exit(0);
    }
    while(1)
    {
        if(a.empty())
            break;
        if(a[0] != 0)
            break;
        a.erase(a.begin());
        n--;
    }
    while(1)
    {
        if(a.empty())
            break;
        if(*a.rbegin() != 0)
            break;
        a.pop_back();
        n--;
    }
    int l = 0;
    int f = 0;
    set < int > s;
    for(int i = 1; i < n; i++)
    {
        if(a[i] == 0 && a[f] == 0)
        {
            s.insert(i);
            s.insert(f);
        }
        f = i;
    }
    cout << (n - s.size()) << ' ';
}

/*
 *	By:- Alchemists
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d%d",&x,&y)
#define riii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rll(x,y) scanf("%lld%lld",&x,&y)
#define rlll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define rs(str) scanf("%s",str)
#define pf printf

#define pii pair<int,int>
#define vpii vector< pii >
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define TC() int __tc; ri(__tc); while(__tc--)
#define vi vector<int>

#define pi(x) printf("%d",x);

int main()
{
	int i=0,n;

	ri(n);

	int temp,count=0,one=0,zero=0;

	bool start=true;

	for(i=0;i<n;i++)
	{
		ri(temp);

		if(temp==0)
		{
			if(zero==1)
			{
				count+=one;
				one=0;
				zero++;
			}
			else
				zero++;
		}
		else
		{
			if(zero==1 && !start)
			{
				zero=0;
				one+=2;
			}
			else if(zero)
			{
				zero=0;
				one++;
			}
			else
				one++;

			start=false;
		}

		//printf("%d %d\n",i,count);
	}

	count+=one;

	pi(count);

	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

int a[101];

int main(){
	int n; cin >> n;
	int ans = 0;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		if (a[i] || (!a[i] && (i > 0 && a[i-1]) && (i + 1 < n && a[i+1])))
			++ans;
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdlib>

#define llu unsigned long long int
#define lli long long int
#define ld long double

using namespace std;

int main(void)
{
    int n,f0=0,l0=0;
    std::cin >> n;

    int arr[n];
    for(int i=0; i<n; ++i)
        std::cin >> arr[i];

    int ocu[n]={0},j=0,temp=1,len;
    for(int i=0; i<n-1; ++i)
    {
        if(arr[i] == 0)
        {
            if(arr[i] == arr[i+1])
                ++temp;
            else
            {
                ocu[j]=temp;
                ++j;
                temp=1;
            }
        }
    }

    if(arr[n-1] == 0)
    {
        ocu[j]=temp;
        len=j+1;
    }
    else
        len=j;

    if(arr[0] == 0)
        f0=ocu[0];
    if(arr[n-1] == 0)
        l0=ocu[len-1];

    if(len == 1 && ocu[0] == n)
    {
        std::cout << "0" << '\n';
        return 0;
    }

    int l,s;
    if(l0 == 0)
        l=len;
    else
        l=len-1;
    if(f0 == 0)
        s=0;
    else
        s=1;

    for(int i=s; i<l; ++i)
        if(ocu[i] > 1)
            n-=ocu[i];

    if(n > 1)
        n-=(l0+f0);
    else
        n-=l0;

    // for(int i=0; i<len; ++i)
    //     std::cout << ocu[i] << ' ';
    std::cout << '\n' << n << '\n';

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        int ans = 0;
        bool home = true, brea = false;
        for (int i = 0; i < n; i++) {
            int tmp;
            scanf("%d", &tmp);
            if (tmp == 1) {
                ans++;
                if (brea && !home) ans++;
                brea = false;
                if (home) home = false;
            }
            else {
                if (!home && !brea) {
                    brea = true;
                }
                else if (!home && brea) {
                    home = true;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

#include <iostream>

using namespace std;

int main() {

	int n;
	cin >> n;

	int v[n], ind1 = -1, ans = n, ind2 = 0, nr = 0;
	for (int i = 0; i < n; i++)
		cin >> v[i];

	for (int i = n-1; i >= 0; i--) {
		if (v[i] == 1) {
			ind1 = i;
			break;
		} else ans--;
	}

	for (int i = 0; i < n; i++) {
		if (v[i] == 1) {
			ind2 = i;
			break;
		} else ans--;
	}

	for (int i = ind2; i <= ind1; i++) {
		if (v[i] == 0)
			nr++;
		else if (v[i] == 1 && nr > 1) {
			ans -= nr;
			nr = 0;
		} else if (v[i] == 1)
			nr = 0;
	}

	if (ans > 0)
		cout << ans << endl;
	else
		cout << 0 << endl;

	return 0;
}

/*Hard Work Beats Talent,When Talent Doesn't Work Hard"*/
#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define fastIO ios::sync_with_stdio(false);cin.tie(0)
#define sii(x) scanf("%d",&x)
#define pii(x) printf("%d\n",x)
#define sll(x) scanf("%lld",&x)
#define pll(x) printf("%lld\n",x)
#define present_set_map(container, element) (container.find(element) != container.end())
#define present_vec(container, element) (find(all(container),element) != container.end())
#define mp make_pair
#define all(x) x.begin(),x.end()
#define all_rev(x) x.rbegin(),x.rend()
#define pb push_back
#define fr first
#define se second
#define MAX 200005
#define INF 1<<60
#define mod 1000000007
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define clr(x) memset(x,0,sizeof(x))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
#define LOOP(itr,x) for(auto itr: x)
#define decimalpoints(x) cout<<setprecision(x)<<fixed;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll a,ll b,ll MOD){ll x=1,y=a;while(b>0){if(b%2 == 1){x=(x*y)%MOD;}b/=2;y = (y*y)%MOD;}return x;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
using namespace std;

const int N=1e2+2;
int arr[N];

int main()
{
    fastIO;
    int n,ans,i,j,k;
    cin>>n;
    ans=0;
    int f=0;
    int start,end;
    start=n;
    end=n-1;
    REP(i,n)
    {
        cin>>arr[i];
        if(arr[i]==1 && f==0)
        {
            f=1;
            start=i;
        }
        if(arr[i]==1)
            end=i;
    }
    for(i=start;i<=end;)
    {
        if(arr[i]==0)
        {
            for(j=i+1;j<=end;j++)
            {
                if(arr[j]==1)
                    break;
            }
            if(j-i==1 && j!=n)
                ans++;
            i=j;
        }
        else if(arr[i]==1)
        {
            ans++;
            i++;
        }
    }
    cout<<ans;
}

#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define fa(i,n) for(int i=0; i<(n); i++)
#define f(i,a,n) for(int i=(a); i<=(n); i++)
#define sc scanf
#define pr printf
#define co cout
#define ci cin
#define pi acos(-1)
using namespace std;
int main(){
    int n,s;vector<int>a(100);
    sc("%i",&n);
    fa(i,n)
        sc("%i",&a[i]);
    s=a[0];
    f(i,1,n-1)s+=(a[i]? 1:(i<n-1 && a[i-1] && a[i+1]));
    pr("%i",s);
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int v[n];
    for (int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    int res=0;
    bool home=true;

    for (int i=0;i<n;i++)
    {
        if (i==n-1)
        {
            if (v[i]==1) res++;
        }
        else
        {
            if (v[i]==0)
            {
                if (v[i+1]==1 and !home) res++;
                else
                if (v[i+1]==0) home=true;
            }
            else
            {
                res++;
                home=false;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long int ll;
const int M = 1e9 + 7;

main()
{

 ll n,a,b , i , temp,ans=0,flag=0,start=0 , en=0;
 string st;
vector <ll> v;

 cin>>n;
 for(i=0;i<n;i++)
 {
     cin>>temp;
   v.push_back(temp);
 }

for(i=0;i<n;i++)

{
    if(v[i]==1)
        en=i;
}

i=0;
while(i<n && v[i]!=1)
{
    i++;
}
start=i;

for(i=start ; i<=en;i++)
{
    if(v[i]==0 && v[i+1]==0)
    {
        while(v[i]==0 && i<n)
        {
            i++;
        }
        i--;
    }
    else ans++;
}
cout<<ans;
  return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n, a, p=0, c=0;
    cin >> n;
    cin >> a;
    if (a==1)
        c++;
    else
        p=2;
    for (int i=1; i<n; i++)
    {
        cin >> a;
        if (a==1)
        {
            c++;
            if (p==1)
            {
                c++;
            }
            p=0;
        }
        else
            p++;
    }
     cout << c;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int count=0;
    int sum=0;
    int i=0;
    if(a[0] == 0)
    while(a[i] == 0)
    {
        i++;
    }
    if(a[n-1]==0)
    {
    while(a[n-1]==0)
    n--;
    }
    for( ; i<n ; )
    {
        if(a[i] == 0)
        {
            count=0;
            while(a[i]==0)
            {
            i++;
            count++;
            }
            if(count<2)
            {
              sum++;
            }
        }
        else if(a[i]==1)
        {
        sum++;
        i++;
        }

    }
    cout<<sum<<endl;
    return 0;
}

#include <iostream>
using namespace std;
int main() {

	long n, arr[10000], counter = 0;
	int akmal = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	for (int i = 0; i < n; i++) {
		if (arr[i] == 1) {
			counter++;
			akmal= 1;
		}
		else if (arr[i] != arr[i + 1] && akmal== 1) {
			counter++;
		}
		else if (arr[i] == arr[i + 1] && arr[i] == 0) {
			i++;
			akmal = 0;
		}

	}
	cout << counter << endl;
	return 0;
}

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,n,m,i,j,t,d,c;
    int arr[100000];
    scanf("%d",&n);
    c=0;
    d=n;
    m=1;

    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);

    }
    if(arr[1]==0&&arr[2]==1)
    {
        d=d-1;
    }
    int f;
    for(i=1;i<=n;i++)
    {
        f=1;
        if(arr[i]==0)
        {
            c++;
        }
        else
        {
            f=0;
            if(c>=2)
            {
               d=d-c;
            }
            c=0;
        }
    }
    if(f==0)
    printf("%d\n",d);
    else
    printf("%d",d-c);

    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		v.push_back(a);
	}
	int ans = 0,l= 0, r = 0;
	if (v.size() == 1 && v[0] == 1)
		cout << 1 << endl;
	else if (v.size() == 1 && v[0] == 0)
		cout << 0 << endl;
	else
	{
		for (int i = v.size() - 1; i >= 0; i--)
		{
			if (v[i] == 1)
			{
				r = i;
				break;
			}
		}

		for (int i = 0; i < n; i++)
		{
			if (v[i] == 1)
			{
				l = i;
				break;
			}
		}
		for (int i = l; i <= r; i++)
		{
			if (v[i] == 1)
				ans++;
			else if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1)
				ans++;
			else if (v[i] == 0 && v[i - 1] == 0)
				continue;
			else if (v[i] == 0 && v[i + 1] == 0)
				continue;
		}
		cout << ans << endl;
	}
	//system("pause");
	return 0;
}

#include <stdio.h>

int main(){
	int n,arr[100]={},sum=0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &arr[i]);
	}
	int act=0;
	for(int i = 0; i < n; i++){
		if(arr[i] == 1){
			sum++;
			act=1;
		}else if(arr[i] == 0 && arr[i+1] == 0){
			i++;
			act=0;
		}else if(act==1 && arr[i]==0 && arr[i+1] == 1){
			sum++;
		}
	}

	printf("%d", sum);

	return 0;
}

#include <stdio.h>
#include <iostream>

using namespace std;
const int n = 100;
int a[n];

int main()
{
	int m = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
	{
		if (a[i] == 1) m++;
		else if (a[i + 1] == 1 && a[i - 1] == 1) m++;
	}
		if (a[0] == 1) m++;
		if (a[n] == 1) m++;

	cout << m;
	printf("\n");
	return 0;

}

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){

	int n;
	cin>>n;
	vector<int>arr(n,0);

	int count = 0;

	for(int i=0;i<n;i++){
		cin>>arr[i];
	}

	for(int i=0;i<n;i++){

		if(arr[i] == 1){
			count++;
		}
		if(arr[i] == 0){
			if(arr[i+1] == 1 && arr[i-1] == 1 && i>0 && i<n-1){
				count++;
			}
		}
	}
	cout<<count<<endl;

	return 0;
}

#include <bits/stdc++.h>
#include <climits>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long int
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define loop(i, L, R) for (int i = L; i < R; ++i)
#define looprev(i, L, R) for (int i = L; i > R; --i)
#define MAX(x, y) (x > y ? x : y)
#define MIN(x, y) (x < y ? x : y)
#define wh(t) while (t--)
#define pii pair<int, int>
#define ppi pair<int, pii>
#define pll pair<ll, ll>
#define ppl pair<ll, pll>
#define vii vector<int>
#define vvi vector<vii>
#define vl vector<ll>
#define vvl vector<vl>
#define maxHi priority_queue<int>
#define maxHl priority_queue<ll>
#define minHi priority_queue < int, vector<int>, greater<int>>
#define minHl priority_queue < ll, vector<ll>, greater<ll>>
#define mod 1000000007
#define inf 1000000000000000001
#define PI 3.1415926535897932384626
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false)
#define endl "\n"
using namespace std;

/*  AH SH*T,  HERE WE GO AGAIN.  */

void CR7()
{

	ll i, j, n, m;

	cin >> n;

	std::vector<int> v(n);

	loop(i, 0, n) cin >> v[i];

	ll beg = n, last = 0;

	loop(i, 0, n)
	{

		if (v[i] == 1)
		{
			beg = i;
			break;

		}

	}

	if (beg == n)
	{

		cout << "0" << endl;
		return ;

	}

	//deb(beg);

	for (int i = n - 1; i >= 0; --i)
	{

		if (v[i] == 1)
		{
			last = i;
			break;

		}

	}

	//deb(last);

	ll total = last - beg + 1, count = 0;

	i = beg + 1;

	while (i < last)
	{

		if (v[i] == 0 && v[i + 1] == 0)
		{
			count += 2;

			loop(j , i + 2, last)
			{
				if (v[j] == 1)
				{
					break;
				}

				i++;

				count++;

			}

			i = i + 2;

		}
		else i++;

	}

	cout << total - count << endl;

}

int32_t main()
{

	IOS;
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T = 1;

//	cin >> T;

	wh(T)
	{

		CR7();

	}
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
    int a[200888];
    int ans[200888];
    main(){
    int n;
    cin >> n;
    int ohir = 0;
    bool bir = false;
    int boshi = 0;
    for(int i = 1 ; i <= n ;i++){
        cin >> a[i];
        if(!bir and a[i]){boshi = i; bir = true;}
        if(a[i])ohir = i;
    }
    if(boshi!=0 and ohir !=0){
        int nollar = 0;
        int soni = 0;
        for(int i = boshi ; i <= ohir;i++){
               if(a[i]==0)soni++;
               else{
                if(soni >= 2) nollar+= soni;
                soni = 0;
               }
        }
        int javob = ohir - boshi;
        javob++;
        javob -= nollar;
        cout << javob;

    }else{
    if(boshi == ohir and boshi != 0)cout << 1;
    else{
        cout << 0;
    }

    }

    }

#include <stdio.h>
#include <string.h>

int main () {
	int a, h = 0;
	scanf ("%d", &a);
	int b[a];
	for (int i = 0; i < a; i++) {
		scanf ("%d", &b[i]);
	}
	for (int i = 0; i < a; i++) {
		if (b[i] == 1) {
			if (b[i+1] == 0 && b[i+2] == 1) {
				i+=1;
				h+=2;
			} else h++;
		}
	}

	printf ("%d\n", h);
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int al[n];
	int k[n], count=0;

	for (int i=0; i<n; i++)
	{
		cin >>al[i];
	}
	for (int i=0; i<n; i++)
	{

			 if (al[i] != 0)
			 {
			 	k[count]=al[i];
			 		count ++;
			 }

	}

	for (int i=1; i<n-1; i++)
	//if (al[0]!=0 || al[n-1]!=0)
	{
	if (al[i-1]!=0 && al[i]==0 && al[i+1]!=0)
			 		{

			 			count ++;

			 		}

	}
		cout << count;

	return 0;

}

#include<bits/stdc++.h>
using namespace std;
int n,ans,a[105];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    ans=n;
    for(int i=1;i<=n;i++)
        if(a[i]==0)
            if(a[i-1]==0||a[i+1]==0)
                ans--;
    cout<<ans<<endl;
}

//In the name of God
//-----gmmj

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <map>
#include <sstream>
#include <ctime>
#include<iomanip>

#define Time printf("\nTime : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC);
#define Rep(I,N) for(int I=0;I<N;++I)
#define For(J,R,K) for(int J=R;J<K;++J)
#define MP make_pair
#define ALL(X) (X).begin(),(X).end()
#define SF scanf
#define PF printf
#define pii pair<long long,long long>
#define Ff first
#define Ss second
#define Sort(v) sort(ALL(v))
#define Test freopen("a.in","r",stdin);
#define Testout freopen("a.out","w",stdout);
#define pb push_back
#define RLL(X) scanf("%I64d",&X);
#define RRLL(X,Y) scanf("%I64d %I64d",&X,&Y);
#define WLL(X) printf("%I64d",X);
#define WWLL(X,Y) printf("%I64d %I64d",X,Y);
#define Loop(N) RLL(N)Rep(i,N)
#define Set(a,n) memset(a,n,sizeof(a))
#define MAXN 100000+9
#define EPS 1e-8

typedef long long ll;

using namespace std;

bool ar[MAXN];

int main()
{
//	Test
	ll n;
	while(cin>>n)
	{
		ll ans =0;
		Rep(i,n)
			cin>>ar[i];
		bool home =1;
		For(i,0,n-1)
		{
			if(ar[i])
				ans++,home =0;
			else if(ar[i+1] && !home)
				ans++,home =0;
			else
				home = 1;
		}
		if(ar[n-1])
			ans++;
		cout<<ans<<endl;;

	}
	return 0;
}

#include <bits/stdc++.h>

#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef char ch;
typedef string st;
typedef int in;

const ll N = 1e5 * 3;

ch a[100000];
ll n, ans, res;
int main() {
	cin >> n;
	for(int i =1;i <= n;++i)
		cin >> a[i];
	for(int i = 1;i <= n;++i) {
	  if(a[i] == '1')
	  	ans++;
	  if(a[i] == '1' && a[i + 1] == '0' && a[i + 2] == '1') {
	  	ans++;
	  	}
		}
	cout << ans;
	return 0;
	}

#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    io
    long n,i,a[101],c=0,ans=0;
    cin>>n;
    for(i=0;i<n;++i)
    cin>>a[i];
    i=0;
    while(a[i]==0)
    i++;
    for(;i<n;++i)
    if(a[i]==1)
    {
        if(c<=1) ans+=c+1;
        else ans+=1;
        c=0;
    }
    else c++;
    cout<<ans;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int read(){
	int a=0,k=1;char c=getchar();
	while (!isdigit(c)){if (c=='-')k=-1;c=getchar();}
	while (isdigit(c)){a=a*10+c-'0';c=getchar();}
	return a*k;
}
int t,n,a[1005];
int main(){
    //freopen("schedule.in","r",stdin);
    //freopen("schedule.out","w",stdout);
	int n;
	n=read();
	for (int i=1;i<=n;i++)
		a[i]=read();
	int ans=0;
	for (int i=1;i<=n-2;i++)
		if (a[i]==1&&a[i+1]==0&&a[i+2]==1) a[i+1]=1;
	for (int i=1;i<=n;i++)
	ans+=a[i];
	printf ("%d\n",ans);
    return 0;
}

#include <iostream>
using namespace std;

int main() {
    long int n,i,count=0,k=0,g;
    cin>>n;
    long int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(k==0 && a[i]==1)
        {k=1;
        g=i;}

        }
        //cout<<g<<" ";
    for(i=g;i<=n-2;i++)
    {
    //  cout<<i<<" ";
        if(a[i]==1)
        count++;
        //cout<<i<<" ";}
        else
        {
            if(a[i+1]==0)
            {
                i++;
            }

            else if(a[i-1]==1 && a[i+1]==1)
            count++;
        }
    }

    if(a[n-1]==1)
    count++;
    cout<<count;
}

#define __USE_MINGW_ANSI_STDIO 0

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int , int > ii;
typedef vector < ii > vii;
typedef vector < bool > vb;
typedef vector < int > vi;
typedef vector < ll > vll;
typedef vector < string > vs;
typedef vector < vll > matrix;

#define DF cout
#ifdef SGD
#define D(...) DF << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define D(...) 404
#endif
#ifdef SGD
#define PERF cerr << "Case #" << (tt+1) << " " << 1.0 * (clock() - t1) / CLOCKS_PER_SEC << " ms" << endl;
#else
#define PERF
#endif

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) { bool first=true; string res="{"; for (const auto &x : v) { if (!first) res+=", "; first=false; res+=to_string(x); } res+="}"; return res; }
void debug_out() { DF << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { DF << " " << to_string(H); debug_out(T...); }

#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define tr(con,it) for (__typeof((con).begin()) it = con.begin(); it != con.end(); it++)
#define wl(x) (cout << (x) << endl)
#define w(x) (cout << (x))
#define r(x) (cin >> (x))
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define ROF(i,a,b) for (int i = (b-1); i >= (a); i--)
#define mp(x,y) make_pair((x),(y))
#define reset(x,v) memset((x),(v),sizeof(x))
#define LSOne(S) (S & (-S))
#define MAXN 100005
#define MAXK 22
#define MDL 1000000007
#define INF 1ll<<60
#define EPS 1e-10
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

string to_str(const int &n){ostringstream stm; stm << n;return stm.str();}
string to_str(const ll &n){ostringstream stm; stm << n;return stm.str();}
template<class T> string tostring(T x, int len = 0) {stringstream ss; ss << x; string r = ss.str(); if(sz(r) < len) r = string(len - sz(r), '0') + r; return r;}
template<class T> void convert(string x, T& r) {stringstream ss(x); ss >> r;}
ll powmod(ll a,ll b) {ll res=1;a%=MDL;for(;b;b>>=1){if(b&1)res=res*a%MDL;a=a*a%MDL;}return res;}
ll modinv(ll a) { return powmod(a, MDL-2); }
ll modinv(ll a,ll m) { return powmod(a, m-2); }
ll nCkMp(ll n, ll k) { ll numerator = 1,denominator = 1;for (int i=0; i<k; i++) numerator = (numerator * (n-i) ) % MDL;for (int i=1; i<=k; i++) denominator = (denominator * i) % MDL;return (numerator*modinv(denominator)) % MDL; }
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return a*(b/gcd(a,b));}
int TT=1,tt;
clock_t t1;

void solve() {t1=clock();
int n,q,res=0;
bool one_seen=false;
int zero_count=0;

 r(n);
 FOR(i,0,n)
 {
  r(q);
  if (q==0) zero_count++;
  else { if (one_seen && zero_count>=2) res-=zero_count; one_seen=1; zero_count=0; }
  if (one_seen) res++;
 }
 if (one_seen) res-=zero_count;
 wl(res);

PERF}

int main() {IO
//r(TT);
 for(tt=0;tt<TT;tt++) solve();
 return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
	int n,i,cnt=0,temp,is=0,start=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&temp);
		if(is==1 && temp==0)
		{
			is=0;
			start=0;
			continue;
		}
		else if(is==1 && temp==1)
			is=0,cnt+=2;
		else if(start==1 && is==0 && temp==0)
			is=1;
		else if(start==1 && is==0 && temp==1)
			cnt++;
		else if (start==0 && temp==1)
			start=1,cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
map <string, int> m;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int j = 0;
	while(a[j] == 0)
		j++;
	n--;
	while(a[n] == 0)
		n--;
	int ans = 0;
	for(int i = j; i <= n; i++) {
		if(a[i] == 1)
			ans++;
		else if(a[i] == 0 && a[i + 1] != 0)
			ans++;
		else if(a[i] == 0 && a[i + 1] == 0){
			while(a[i] == 0)
				i++;
			i--;
			continue;
		}
	}
	cout << ans;
}
//8775286
//87474329627

#include <bits/stdc++.h>

using namespace std;

const int SIZE = 1e2 + 5;

int main(){
	int n, a[SIZE], u;

	u = 0;
	memset(a, 0, sizeof(a));

	cin >> n;

	for(int i = 0; i < n; i++)
		cin >> a[i];

	u += a[0];

	for(int i = 1; i < n; i++)
		if(a[i] || (!a[i] && a[i - 1] && a[i + 1])) u++;

	cout << u << endl;

	return 0;
}

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<iostream>
using namespace std;

int a[505];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==1)
            ans++;
        if(a[i]==0&&a[i-1]==1&&a[i+1]==1)
            ans++;
    }
    cout<<ans<<endl;
}

#include<iostream>
using namespace std;
int main()
{
	int a[100];
	int n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]==1)sum++;
		if(a[i]==0 && a[i-1]==1 && a[i+1]==1)sum++;
	}
	cout<<sum;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int SIZE = 2e2 + 5;

int main(){
	int i, n, a[SIZE], u;

	u = 0;
	memset(a, 0, sizeof(a));

	cin >> n;

	for(i = 0; i < n; i++){
		cin >> a[i];

		if(a[i]) u++;
	}

	for(int i = 1; i < n; i++)
		if(!a[i] && a[i - 1] && a[i + 1]) u++;

	cout << u << endl;

	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdlib.h>
#include<cstring>
#include<queue>
#include <vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<map>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int res=0,act=0;
    int* cal=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>cal[i];
    }
    for(int i=0;i<n;i++)
    {
        if((cal[i]==1)) {res++;act=1;}
        else {
            if((res!=0)&&(cal[i+1]==1)&& (act==1)) {res++;}
            act=0;
        }
    }
    cout<<res<<endl;
}

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

    int main(void)
    {
        int n, i, index = -1, cont = 0, cont1 = 0; cin >> n;
        int arr[n];
        for ( i = 0; i < n; i++)
        {
            cin >> arr[i];
            if(arr[i] == 1)
                cont++;
            if(index == -1 && arr[i] == 1)
            {
                index = i;
            }
        }
        for ( i = index; i < n, cont; i++)
        {

            if(arr[i] == 0 && arr[i+1] == 0)
            {

                while (arr[i] == 0)
                {
                    i++;
                }
                i--;
            }
            else if(arr[i] == 1)
            {
                cont--;
                cont1++;
            }else if(arr[i] == 0)
                cont1++;
        }
        cout << cont1;
        return 0;
    }

#include<stdio.h>
int main()
{
    int a[105];
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]==1)
            {
                sum++;
                if(a[i+1]!=1)
                {
                    for(int j=i+1;j<n;j++)
                    {
                        if(a[j]==1&&j-i<=2)
                        {
                          //  printf("%d%d\n",i,j);

                            sum++;
                        }
                        continue;
                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

#include <iostream>
using namespace std;

int main() {
	// your code goes here
    int n;
	cin>>n;
	int a[n];

	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int mum=a[1];

	for(int i=2;i<n;i++){
		if ((a[i]==0 and a[i+1]==0) or (a[i]==0 and a[i-1]==0)){
			mum=mum+0;
		}

		else mum=mum+1;
	}
	if( a[n]==0){
		cout<<mum;

	}
	else if(a[1]==1 and n==1){
		cout<<mum;
	}

	else cout<<mum+1;
	return 0;
}

#include <iostream>
using namespace std;
int n, a[10001];
int ans;
int main()
{
    cin >> n;
    for (register int i = 1;i <= n;i ++) cin >> a[i];
    ans = n;
    for (int i = 1;i <= n;++ i)
    {
        if(!a[i])
        {
            if(!a[i - 1] || !a[i + 1])
            {
                ans --;
            }
        }
    }
    cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[105]={0},ans=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
	  if(a[i]==1)ans++;
	  if(a[i]==1&&a[i+1]==0&&a[i+2]==1)	ans++;
	}
    cout<<ans;
 return 0;
}

#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int lessons,result=0,sup,x=0;
queue <int> lesson;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>lessons;
    for(int i=0;i<lessons;i++){
        cin>>sup;
        lesson.push(sup);
    }
while(lesson.front()==0&&lesson.size()>0){
            lesson.pop();
    }
    while(lesson.size()>0){
        if(lesson.front()==0){
            lesson.pop();
            if(lesson.size()==0){
                result+=0;
            }
            else if(lesson.front()==0){
                while(lesson.front()==0&&lesson.size()>0){
                    lesson.pop();
                }
            }

            else{
                result+=2;
                lesson.pop();
            }
        }
        else{
            result++;
            lesson.pop();
        }
    }

cout<<result;

return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int n,a[101],s2=0,t[2];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		t[a[i]]++;
		if (a[i-2]==1&&a[i]==1&&a[i-1]==0) s2++;
	}
	cout<<s2+t[1];
	return 0;
}

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,i,sum=0;
    int a[110];
    cin>>n;
    memset(a,0,sizeof(a));

    for(i=1;i<=n;i++){
        cin>>a[i];
    }
        for(i=1;i<=n;i++){
            if(a[i]==0&&(a[i-1]==0||a[i+1]==0))
                continue;
            else
                sum++;
        }
        cout<<sum<<endl;
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> pair;
    int n;
    cin >> n;
    while (n--) {
        int c;
        cin >> c;
        pair.push_back(c);
    }
    pair.push_back(-1);
    pair.push_back(-1);
    int count=0;
    for(int i=0 ; i<pair.size()-2 ;) {
        if(pair[i] == 1) {
            count++;
            if(pair[i+1] == 0 && pair[i+2] == 1) {
                count++;
                i += 2;
            } else i++;
        } else i++;
    }
    cout << count;

    return 0;
}

#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		sum++;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==1&&a[i+1]==0&&a[i+2]==1)
		sum++;
	}
	printf("%d",sum);
	return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;

int a[110];

int main(){
    int n;
    while(~scanf("%d",&n)){
        int sum = 0;
        for(int i = 0; i < n; i++)
            scanf("%d",&a[i]);
        int i = 0;
        while(a[i] == 0 && i < n)
            i++;
        int j = n-1;
        while(a[j] == 0 && j > 0)
            j--;
        for(; i < j;){
            if(a[i] == 0 && a[i+1] == 0){
                while(i < j && a[i] == 0)
                    i++;
            }
            else{
                a[i] = 1;
                i++;
            }
        }
        for(int i = 0; i < n; i++)
            sum += a[i];
        printf("%d\n",sum);
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
int t[101];

int main()
{
    int n,ans;
    cin >>n;
    for(int i=0;i<n;i++) {
    cin>>t[i];
    }
    ans=0;
    if (t[0]==1){
    ans++;

    }

    for (int i=1;i<n-1;i++){
    if (t[i]==1)
    ans++;
    else {
    if (t[i+1]==t[i-1]==1)
    ans++;

    }

    }
 cout<<ans;

    return 0;
}

// Librerías útiles.
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <set>
#define FOR(i, from, to) for (int i = (from) ; i < to ; i++)
#define FOREACH(obj, it) for (typeof((obj).begin()) it = (obj).begin() ; it != (obj).end() ; it++)
#define FOREACHR(obj, it) for (typeof((obj).rbegin()) it = (obj).rbegin() ; it != (obj).rend() ; it++)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define SYNC ios_base::sync_with_stdio(0);
#define CONV(from, to) if (true) {stringstream ss; ss << from; ss >> to;}
#define ri(i) scanf("%d",&i);
#define rii(i,j) scanf("%d%d",&i,&j);
#define riii(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define EPS 1e-9
#define PI 3.1415926535897932384626
#define dprintf if(debug) printf
bool debug=false;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

typedef pair<int, int> ii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;

typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, vi> miv;

int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
int mcm(int a, int b){ return a * b / gcd(a, b); }
int sq(int a) { return a*a; }
int pot(int a, int b){ return b ? sq(pot(a, b >> 1))*(b & 1 ? a : 1) : 1; }

int main(){

	int n;
	ri(n);
	int prev,now,c=0;
	bool on=false;
	ri(prev);
	on=prev;
	c+=prev;
	int hmz=(prev==0);
	FOR(i,0,n-1){
		ri(now);
		hmz=(now ? 0 : hmz+1);
		c++;
		c-=(hmz==2 ? 2 : (hmz>2 ? 1 : 0));
	}
	cout<<c-hmz<<endl;

}

#include<bits/stdc++.h>

#define lld long long int
#define FOR(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FOR(i,1,n+1)
#define all(x) x.begin(),x.end()
#define LET(x,a) __typeof(a) x(a)
#define IFOR(i,a,b) for(LET(i,a);i!=(b);++i)
#define EACH(it,v) IFOR(it,v.begin(),v.end())
#define PB push_back
#define sz size()
#define pii pair<int, int>
#define pll pair <lld ,lld>
#define MP make_pair
#define fill(x,v) memset(x,v,sizeof(x))
#define scan(v,n) vector<int> v(n);rep(i,n)cin>>v[i];
#define vi vector<int>
#define MOD 1e9 + 7
#define F first
#define S second

using namespace std;

lld modpow(lld a,lld n,lld temp){lld res=1,y=a;while(n>0){if(n&1)res=(res*y)%temp;y=(y*y)%temp;n/=2;}return res%temp;}
int main()
{
    int N;
    cin >> N;
    int prev = -1;
    int ans = 0;vector <int> arr(N);
    FOR(i, 0, N)
        cin >> arr[i];

    int ind = 0;
    bool done = false;
    FOR(i, 0, N)
    {
        if(arr[i] == 0)
            ans++;
        else
        {
            ind = i;
            done = true;
            break;
        }
    }
    bool flag = true;

    if(done == true)
    {
        FOR(i, ind, N)
        {
            if(arr[i] == 0 && arr[i + 1] == 0)
            {
                ans += 1;
                flag = false;
            }
            if(arr[i] == 1 && arr[i-1] == 0 && flag == false)
            {
                flag = true;
                ans += 1;
            }

        }
    }
    if(arr[N - 1] == 0 && done == true)
        ans++;

    cout << N - ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[1005];
	cin>>n;
	bool f1 = 0;
	int loc = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] == 1 && !f1){
			loc = i+1;
		    f1 = 1;
		}

   }
   f1 =0;
   int loc1 = n-1;
   for(int i=n-1;i>=0;i--){
   	   if(a[i] == 1 && !f1){
			loc1 = i+1;
		    f1 = 1;
		}
   }
   int cnt = 1;
   for(int i=loc;i<loc1;i++){
   	if( i + 1 < n && a[i] ==0 && a[i+1] == 0){
   		    i++;
			continue;
	   }
	   cnt++;
   }
   cout<<cnt;
	return 0;
}

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

int main()
{
 int n,counter1=0,counter2=0;
 cin>>n;
 vector<int>vec(n);
 for(int i=0;i<n;i++)
    cin>>vec[i];

 int j=0;
 while(vec[j]==0){
    vec.erase(vec.begin()+j);
    if(vec.size()==0){
        cout<<0;
        return 0;
    }
 }

 int k=vec.size()-1;
 while(vec[k]==0){
    vec.erase(vec.begin()+k);
    k--;
 }
 for(int i=0;i<vec.size();i++){
   if(vec[i]==1){
     counter1++;
     if(counter2<2)
        counter1+=counter2;
   }
   else
    counter2++;

 }
 cout<<counter1;

    return 0;
}

/*
* @Author: Krishna
* @Date:   2015-12-23 19:27:14
* @Last Modified by:   Krishna
* @Last Modified time: 2015-12-23 19:52:58
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <set>
#include <omp.h>
#include <cstring>
#include <map>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define loop(i,x,y) for(int i = x; i < y; ++i)

using namespace std;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<int,int>::iterator miit;
int max (int a, int b) { return a > b ? a : b;}
int min (int a, int b) { return a < b ? a : b;}
int gcd(int a, int b){ return (b==0)? a : gcd(b, a%b);}

int main() {
	int n;
	cin >> n;
	int a[n];
	rep(i,n) cin >> a[i];
	int pairs = n;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		int x = a[i];
		if(x == 0 && i == 0) pairs--;
		else if(x == 0) cnt++;
		else {
			if(cnt >= 2)
				pairs -= cnt;
			else if(cnt == 1 && i + 1 == n)
				pairs--;
			else
				cnt = 0;
		}
	}
	printf("%d\n",pairs-cnt);
	//system("pause");
	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
typedef long long int LL;
const int INF=1e9;
const LL inf=1e16;

const int M=100+5;
int num[M];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		mem(num,0);
		for(int i=0;i<n;++i)
		 scanf("%d",&num[i]);
		int ans=0;
		for(int i=0;i<n;++i)
		{
			if(num[i])
			{
				int t=0,sum=0;
				for(int j=i;j<n;++j)
				{
					if(!num[i])
					 t++;
					else
					 t=0;
					sum++;
					if(t>1)
					{
						sum-=2;
						i++;
						break;
					}
					i++;
				}
				if(t==1)
				 ans--;
				ans+=sum;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
int n;
cin>>n;
int a[n];
int b;
for(int i=0; i<n;i++){
cin>>b;
a[i]=b;
}
int counter=0;
if(a[0]==1){
            counter++;}
for(int j=1;j<n-1;j++){
if(a[j]==1)
{
counter++;
}
if(a[j]==0&&a[j+1]==1)
{
                      if(a[j-1]==1)
                      {
                                   counter++;
                                   }

}
}
if(a[n-1]==1){
counter++;}
cout<<counter;
return 0;

}

#include<iostream>

using namespace std;
int main()
{
int n;
int a[100];
int i;
int sol=0;
cin>>n;
for(i=0;i<n;i++)
    cin>>a[i];

for(i=0;i<n;i++)
{
    if(a[i]==0)
    {}
        if(a[i]==1)
        {sol++;}

    if(a[i]==0&&a[i-1]==1)
    {sol++;}
}
cout<<sol;
    return 0;
}

#include <iostream>

using namespace std;

int a[110] , zf , zs , g;

int main()
{
    int n;
    cin>>n;
    for(int i = 0;i < n;i++)
        cin>>a[i];
    if(n == 1)
    {
        if(a[0] == 1)
            cout<<1;
        else
            cout<<0;
        return 0;
    }
    for(int i= 0;i < n;i++)
        if(a[i] == 1){
            zf = i;
            break;
        }
 //   cout<<zf<<endl;
    for(int i = n-1;i >= 0;i--)
        if(a[i] == 1){
            zs = i;
            break;
        }
   // cout<<zs<<endl;
    for(int i = zf;i < zs;i++)
    {
        if(a[i] == 0 && a[i+1] == 0)
            g++;
    }
    if(zs == zf && zs == 0)
        cout<<"0";
    else
        cout<<(zs-zf)-(2*g)+1;
    return 0;
}

#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	int a[n+10];
	for(i=1;i<=n;i++)
	   scanf("%d",&a[i]);
	   int j;
		int answer=n;
   if(n==1)
     {
     	  if(a[1]==1)
     	    printf("1");
     	   else
     	   printf("0");
     	   return 0;
	  }
	else if(a[1]==0)
	 {
	 	answer--;
	 	for(j=2;j<=n;j++)
	 	 {
	 	 	if(a[j]==0)
	 	    answer--;
	 	  else
	 	     break;
		  }
	 	 for(;j<n;j++)
	 	 {
	 	 	  if(a[j]==0&&a[j+1]==0)
	 	 	    {

	 	 	    	   for(i=j;j<=n;j++)
	 	 	    	  {
	 	 	    	  	   if(a[i]==0)
	 	 	    	      answer--;
	 	 	    	      else
	 	 	    	      break;
						}
					i=j;
	 	 	 }

		  }
		  if(a[n-1]==1&&a[n]==0)
		   answer--;
	 }
	 else
	 {

	 	 for(j=2;j<n;j++)
	 	 {
	 	 	  if(a[j]==0&&a[j+1]==0)
	 	 	    {

	 	 	    	   for(i=j;j<=n;j++)
	 	 	    	  {
	 	 	    	  	   if(a[j]==0)
	 	 	    	      answer--;
	 	 	    	      else
	 	 	    	      break;
						}
					i=j;
	 	 	 }

		  }
		  if(a[n-1]==1&&a[n]==0)
		   answer--;

	 }
	printf("%d",answer);
	return 0;

}

//#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
//ifstream cin("input.txt");
//ofstream cout("output.txt");
vector <int> A;
int main()
{
	int N, K = 0, a, t = 0;
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)	cin >> A[i];
	if (A[0] == 1) K = 1;
	if (N > 1 && (A[1] == 1 && A[0] == 0 || A[0] == 1 && A[1] == 0)) K = 1;
	if (N > 1 && A[0] == 1 && A[1] == 1) K = 2;
	for (int i = 2; i < N; ++i)
	{
		if (A[i] == 1 ) K++;
		if (A[i] == 1 && A[i-1] == 0) K += 2;
	}
	cout <<K;

	return 0;
}

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

ll gcd(ll a,ll b){
	ll x;
	while(b){
		x = a;
		a = b;
		b = x % b;
	}
	return a;
}

ll lcm(ll a,ll b){
	return a*b/gcd(a,b);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("code.in","r",stdin);
	//freopen("code.out","w",stdout);
#endif
	int n,x;
	cin >> n;
	bool add= false;
	vector<int>v;
	for(int i=0;i<n;++i){
		cin >> x;
		if(x == 1)add=true;
		if(add)v.push_back(x);
	}

	while(v.size() && v.back() == 0){
		v.pop_back();
	}

	int ans = 0;
	if(!v.empty())
	for(int i=0;i<v.size()-1;++i){
		if(v[i]==0 && v[i+1]==0){
			++ans;
			while(v[i] == 0 && i <v.size())++i;
		}
	}

	cout << max(0,(int)v.size()-2*ans) << endl;
}

#include <bits/stdc++.h>
/** I'm Klaus, Nicklaus ... npardoa@unal.edu.co

 * **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
int n, m;
int a[501][501];
int dp[501][501];
int go(int i, int j){
	//cout<<s<<endl;
	if(i == n) return 0;
	if(dp[i][j] != -1) return dp[i][j];
	int& ans = dp[i][j];
	ans = 0;
	ans = max(ans,go(i+1, 0) ^ a[i][j] );
	if(j+1 < m )ans = max(ans,go(i, j+1));
	return ans;
}
vector<int> ans;
void getdp(int i, int j){
	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	if(i == n ) return;
	if( (dp[i+1][0]^a[i][j]) == dp[i][j]){
		ans.push_back(j+1);
		getdp(i+1,0);
	}else{
		getdp(i,j+1);
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	int n;
	cin>>n;
	int ans = 0;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin>>a[i];
	int j = -1;
	for(int i=0; i<n; i++){
		if(a[i] && j == -1){
			j=i;
			ans++;
		}else if(a[i]){
			if(i - j >= 3) continue;
			ans += (i-j);
			j=i;
		}
	}
	cout<<ans<<endl;
 	return 0;
}

#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    int a[n];
    int temp = -1;

    for (int i = 0; i<n; i++)
    {
        cin >> a[i];
        if (a[i] == 1)
        {
            temp = i;
        }
    }

    int res = 0;
    bool check = false;

    for (int i = 0; i<n; i++)
    {

        if (i > temp)
        {
            break;
        }

        if (a[i] == 1)
        {
            check = true;
            res++;
        }

        else
        {
            if (check)
            {
                if (a[i] == 0)
                {
                    if (i < n-1)
                    {
                        if (a[i+1] == 0)
                        {
                            i++;
                        }
                        else
                        {
                            res++;
                        }
                    }
                }
            }
        }
    }
    cout << res;
    return 0;
}

#include <bits/stdc++.h>
#include <cstdio>
#include<cmath>
#include<algorithm>
#include <vector>
using namespace std;

int main()
{
	int  n,i,count=0,a[101];
	cin>>n;
	for(i=0;i<n;i++)
	    cin>>a[i];
	if(n==1)
	{
	    if(a[0]==0)
	        cout<<0;
	    else
	        cout<<1;
	}
	else
	{
	    for(i=0;i<n-1;i++)
            if(a[i]==1)
	            count++;
	   if(count==0)
	        cout<<count;
	   else
	       cout<<count+1;
	}
    return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<memory.h>
#include<vector>
#include<stdio.h>
#include<map>
#include<queue>
#include<sstream>
#include<cmath>
#include<math.h>
#include<stack>
using namespace std;
int n;
int a[111];
int main(){
	cin >> n;
	int in = -1;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (in == -1 && a[i] == 1)
			in = i;
	}
	int c = 0;
	int ans = 0;
	if (in!=-1)
	for (int i = in; i < n; i++)
	{

		if (a[i] == 1)
			++ans,c=0;
		if (a[i] == 0)
			++c,++ans;

		if (c >= 2)
			ans -= 2;
	}
	if (a[n - 1] == 0 && in!=-1)
		--ans;
	cout << ans << endl;
}

#include<iostream>
using namespace std;
int main()
{
	int n,ans,a[105],flag=1,cnt=0,num=0,pum=0;
	cin>>n;
	cin>>a[0];
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
		ans++;
		if(a[i]+a[i-1]==0)
		cnt++;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
		num++;
		else
		break;
	}
	for(int i=n-1;i>=0;i--)
	{
		if(a[i]==0)
		pum++;
		else
		break;
	}
	if(ans!=0&&cnt)
	cout<<n-num-cnt-1-pum<<endl;
	else if(ans!=0)
	cout<<n-num-pum<<endl;
	else
	cout<<0<<endl;
	return 0;
}

#include <bits/stdc++.h>

#define l(i,n) for(int i=0;i<n;i++)
#define	all( gg )	gg.begin(),gg.end()

#define pii pair<int,int>

#define __DEBUG__   0
#define DB()        if(__DEBUG__) cout<<__LINE__<<":\tI'm in!"<<endl
#define DB1(x)      if(__DEBUG__) cout<<__LINE__<<":\t"<<#x"="<<(x)<<endl
#define DB2(x,y)    if(__DEBUG__) cout<<__LINE__<<":\t"<<#x"="<<(x)<<"\t"<<#y"="<<(y)<<endl
#define DBpair(x)   if(__DEBUG__) cout<<__LINE__<<":\t"<<"("<<x.first<<","<<x.second<<")"<<endl
typedef long long LL;

using namespace std;

int main(){
std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("in.txt","r",stdin);
    int n;
    cin>>n;
    bool a[n];
    l(i,n){
        cin>>a[i];
    }
    int ans=0;
    int stk=0;
    l(i,n){
        if(a[i]){
            if(stk==0) ans++;
            else if(stk==1) ans+=2;
            else ans++;
            stk=0;
        }
        else{
            if(i!=0) stk++;
        }
    }
    cout<<ans<<endl;
return 0;
}

// Librerías útiles.
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <set>
#define FOR(i, from, to) for (int i = (from) ; i < to ; i++)
#define FOREACH(obj, it) for (typeof((obj).begin()) it = (obj).begin() ; it != (obj).end() ; it++)
#define FOREACHR(obj, it) for (typeof((obj).rbegin()) it = (obj).rbegin() ; it != (obj).rend() ; it++)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define SYNC ios_base::sync_with_stdio(0);
#define CONV(from, to) if (true) {stringstream ss; ss << from; ss >> to;}
#define ri(i) scanf("%d",&i);
#define rii(i,j) scanf("%d%d",&i,&j);
#define riii(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define EPS 1e-9
#define PI 3.1415926535897932384626
#define dprintf if(debug) printf
bool debug=false;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

typedef pair<int, int> ii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;

typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, vi> miv;

int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
int mcm(int a, int b){ return a * b / gcd(a, b); }
int sq(int a) { return a*a; }
int pot(int a, int b){ return b ? sq(pot(a, b >> 1))*(b & 1 ? a : 1) : 1; }

int main(){

	int n;
	ri(n);
	int prev,now,c;
	bool on=false;
	ri(prev);
	on=prev;
	c+=prev;
	int hmz=(prev==0);
	FOR(i,0,n-1){
		ri(now);
		hmz=(now ? 0 : hmz+1);
		if(on){
			if(prev==0 and now==0){ on=false; c--;}
			else c++;
		}
		else{
			if(now==1){
				c++;
				on=true;
			}
		}
		prev=now;
	}
	cout<<c-hmz<<endl;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,d,tmp = 0,cnt = 0,sum = 0,i,j,a,b,c,mx = LLONG_MIN;
    vector<int>v;
    string str,str1;
    map<int,int>mp;
    cin>>n;
    for(i = 0;i < n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    stack<int>st;
    if(v[0]==1)
        st.push(1);
      if(v[n-1]==1)
        st.push(1);
    for(i = 1;i+1 < n;i++)
    {
        if(v[i]==1)
        {
          st.push(v[i]);
        }
        else if(v[i]==0 && v[i-1]==1 && v[i+1]==1)
            st.push(v[i]);
    }

    cout<<st.size()<<endl;
    return 0;
}

/*
 *	By:- Alchemists
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d%d",&x,&y)
#define riii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rll(x,y) scanf("%lld%lld",&x,&y)
#define rlll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define rs(str) scanf("%s",str)
#define pf printf

#define pii pair<int,int>
#define vpii vector< pii >
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define TC() int __tc; ri(__tc); while(__tc--)
#define vi vector<int>

#define pi(x) printf("%d",x);

int main()
{
	int i=0,n;

	ri(n);

	int temp,count=0,one=0,zero=0;

	for(i=0;i<n;i++)
	{
		ri(temp);
		if(temp==0)
		{
			if(zero==1)
			{
				count+=one;
				one=0;
				zero++;
			}
			else
				zero++;
		}
		else
		{
			if(zero)
			{
				zero=0;
				one++;
			}
			else
				one++;
		}
	}

	count+=one;

	pi(count);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int idx1=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==1)
        {
            idx1=i;
            break;
        }
    }
    int  idx2=-1;
    for(int i=n-1;i>-1;i--)
    {
        if(a[i]==1)
        {
            idx2=i;
            break;
        }
    }
    if(idx2!=-1)
    {
        ans++;
    }
    for(int i=idx1;i<idx2;i++)
    {
       if(a[i]==1 || a[i]==0 && a[i+1]==1)
       {
           ans++;
       }
       if(a[i]==0 && a[i+1]==0)
       {
           i++;
       }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int a[101];
int main()
{
   // freopen("asd.inp","r",stdin);
    int n;
    cin >>n;
    for (int i = 1;i <= n; i++) cin >> a[i];
    int ans  = n;
    int u = 1;
    if (!a[1] && a[2]) ans--;
    while (u < n)
    {
        int v = u;
        if (!a[u])
        {
            while (!a[v+1]&& v<n) v++;
            if (v - u >0) ans-= v-u+1;
        }
        u = v+1;
    }
    int k = n;
    if (!a[n]&& a[n-1]) ans--;
    cout << max(0,ans);
}

#include<bits/stdc++.h>

using namespace std;

bool a[ 101 ] ;
int n , m , k ,  s = 0 , sum = 0 , ans = 0 ;

void init(){
	scanf( "%d" ,&n ) ;
	for( int i = 1 ; i <= n ; i ++ ){
		cin >> a[ i ] ;
	}
}

void work(){
	while( !a[ ++s ] ) ;
    for( s = 0 ; s <= n ; s ++ ){
    	if( a[ s ] ){
        	if( sum < 2 ){
        		ans += sum ;
			}
        	sum = 0 ;
			ans ++ ;
     }
     else
	 sum ++ ;
	}
    printf( "%d\n" ,ans ) ;
}

int main()
{
	init() ;
	work() ;
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
	// your code goes here

	int n;
	cin>>n;
	vector<int>a;
	for(int i = 0; i < n; i++){
		int temp;
		cin>>temp;
		a.push_back(temp);
	}

	int sum = n;
	if(a[0] == 0){
		sum -= 1;
	}
	for(int i = 1; i < n; i++){

		if(a[i] == 0){
		    int counter = 1;
		    for(int idx = i + 1; idx < n; idx++){
		        if(a[idx] == 1){
		            break;
		        }
		        else{
		            counter++;
		        }
		    }
		    if(counter >= 2 && sum - counter >= 0){
		        sum -= counter;
		    }
		}

	}

	if(a[n-1] == 0 && sum > 0){
		sum -= 1;
	}

	cout<<sum<<endl;
	return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    vector <int> nmb;
    nmb.resize(n);
    bool loh = false;
    int fio = 0;
    for (int i = 0;i < n;++i) {
        cin >> nmb[i];
        if (nmb[i] == 1 && !loh) {
            loh = true;
            fio = i;
        }
    }
    for (int i = fio;i < n;++i)
        if (nmb[i] == 0 && nmb[i + 1] == 0) {
            for (;i + 1 < n;++i)
                if (nmb[i + 1] == 1)
                    break;
        } else {
            ans++;
        }
    cout << ans;
}

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	int a;
	cin >> a;
	int bin[a];
	int count = 0;
	for (int i; i < a; i++) {
		cin >> bin[i];
	}
	for (int i = 1; i < a; i++) {
		if ((bin[i-1]) || (bin[i])) {
			count++;
		}
	}
	if ((bin[a-2]) && (bin[a-1] == 0)) {
		count--;
	}
	if (a == 1) {
		count = bin[0];
		cout << count;
		return 0;
	}
	if ((a == 2) && (bin[0]) && (bin[1] == 0)) {
		count = 1;
	}
	cout << count;
}

#include <iostream>

using namespace std;

int main()
{
    int n, liczba = 0, przerwa = 0;

    cin >> n;

    int *tab = new int [n];

    for(int i = 0; i < n; i++)
    {
        cin >> tab[i];
    }

    int j = n-1;

    while(tab[j] == 0)
        j--;

    for(int i = j; i >= 0; i--)
    {
        if(tab[i] == 1)
            liczba++;
        else if(tab[i] == 0 && tab[i-1] == 1)
            liczba++;
        else if (tab[i] == 0 && tab[i-1] == 0)
            {

                while(tab[i-2] == 0)
                {
                    przerwa++;
                    i--;
                }

            }
    }

    cout << liczba - przerwa;

    delete[] tab;
}

#include <stdio.h>
#include <string.h>

int main(){

	int n, a[105];
	int i, range[105] = {0}, count, br = 0, res = 0;

	scanf("%d", &n);

	count = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);

		if (a[i] == 1)
		{
			range[count] = i;
			count += 1;
		}
	}

    res = (range[count-1] - range[0]);

    if (res > 0)
    {
    	res += 1;
	}

    if (count > 0)
	{
	    for (i = range[0]; i < range[count-1]; i++)
	    {
	    	if (a[i] == 0)
	    	{
	    		br += 1;
			}
			else if (a[i] == 1)
	    	{
	    		br = 0;
			}

	    	if (br >= 2)
	    	{
	    		res -= br;
			}
	    }
	}

    printf("%d\n", res);

	return 0;
	}

#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n;cin>>n;
   vector<int> a(n);
   for(int i=0;i<n;i++)
   cin>>a[i];
   int p=0,q=0;
  for(int i=0;i<n;i++)
  {
      if(a[i]==1)
      {p=i;break;}
  }
   for(int i=n-1;i>=0;i--)
   {
       if(a[i]==1)
       {q=i;break;}
   }
   int c=0;
   for(int i=p;i<=q;i++)
   {
       if(a[i]==0)
       {
       if(a[i]==a[i+1]||a[i]==a[i-1])
       continue;}
       c++;
   }
   cout<<c;
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ar[20007];
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>ar[i];
    //ar[n+1]=1;
    int left=1,right=n;
    for(int i=1; i<=n; i++)
    {
        if(ar[i]==1)
        {
            left=i;
            break;
        }
    }
    for(int i=n; i>=1; i--)
    {
        if(ar[i]==1)
        {
            right=i;
            break;
        }
    }
    int sum=right-left+1;
  //  cout<<sum<<endl;
    for(int i=left; i<=right; i++)
    {
        if((ar[i]==0)&&(ar[i+1]==0))
        {
            sum-=2;
           // cout<<i<<endl;
            i++;
        }
    }
    cout<<sum<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,a,k,l,d;
main(){
cin>>n;
while(n--){
    cin>>a;
    if(a==1)k=1;
    if(k==1){
        if(a==1)d++,l=0;
        else l++,d++;
        if(l==2)k=0,d-=2;
    }
}
cout<<(a?d:max(0,d-1));
}

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

int main()
{

   int cnt,i,j,k,zro,arr[101],koyta;

   cin>>koyta;
   for(i=1;i<=koyta;i++)
   {
       cin>>arr[i];
   }

   zro=0;
   cnt=0;

   for(i=1;i<=koyta;i++)
   {
       if(arr[i]==0)
       {
           zro++;
       }

       else if(arr[i]==1)
       {
           cnt++;
           if(zro==1)
           {
               cnt++;
           }
           zro=0;
       }
   }

   cout<<cnt<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define fr first
#define sc second
#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
// taskkill /im new.exe /t /f
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    if(a.first!=b.first)
    return (a.first < b.first);
    else return b.second < a.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
   //freopen("error.txt", "w", stderr);
  freopen("output.txt", "w", stdout);
#endif

 ll T = 1 ;
// cin>>T;
for(ll t=0;t<T;t++)
{
  ll n ;
  cin>>n;
  ll arr[n];
  for(ll i = 0;i<n;i++){
    cin>>arr[i];
  }
  ll c0 = 0 , ans = 0 , i = 0;
  while(arr[i]==0&&i<n) i++;
  for(;i<n;i++){
    if(arr[i]==0){
      c0++;
    } else {
      if(c0<=1){
        ans = ans + c0 ;
      }
      ans++;
    }
  }
  cout<<ans<<endl;
}

  return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define endl '\n'
#define llint long long int
#define vint vector<int>
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int ans, n, a[101], count, z_c, z_buff;
    bool st, flg;
    z_buff = 0;
    a[0] = 0;
    count = 0;
    z_c = 0;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
    	cin >> a[i];
	}
	for(int i = 0 ; i < n ; i++){
		if(a[i] == 1 && st == false){
			st = true;
		}
		if(st){
			if(a[i] == 1){
				count++;
				if(z_c < 2){
					count += z_c;
				}
				z_c = 0;
			}
			if(a[i] == 0){
				z_c++;
				//z_buff++;
			}
		}
	}
    cout << count;
    return 0;
}

//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <utility>
#include <numeric>
#include <set>
#include <math.h>
#include <bitset>
#include<fstream>
using namespace std;
int main()
{
 int n;
 cin>>n;
 vector<int> L;
 for(int i=0;i<n;i++)
 {
    int e;
	cin>>e;
	L.push_back(e);
 }
 int c=L.size();
 vector<bool> v(L.size(),false);
 if(L.size()>1)
 {
	int c=L.size();

   for(int i=0;i<L.size()-1;i++)
   {

	if(L[i]==0 && L[i+1]==0)
	{
	  v[i]=true;
	  v[i+1]=true;
	 // cout<<L[i]<<" "<<L[i+1]<<endl,
	 // cout<<i<<endl;
	 c=c-2;
	 i=i+1;
	}
   }
   // cout<<v[0]<<" dd "<<v[L.size()-1]<<endl;
   if((L[0]==0 && v[0]==false))
	{
	v[0]=true;
	 c--;
	}
	if((L[L.size()-1]==0 && v[L.size()-1]==false))
	{
	v[L.size()-1]=true;
	 c--;
	}
   cout<<c<<endl;
 }
 else
 {
   cout<<0<<endl;
 }
return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a[100];
    int n, i, sum = 0, tmp;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    i = 0;
    while (a[i] == 0) {
        i++;
    }

    for (; i < n; i++) {
        if (a[i] == 1) {
            sum++;
        } else {
            tmp = i + 1;
            while (a[tmp] == 0 && tmp < n) {
                ++tmp;
            }
            if ((tmp - i) >= 2)
                i = tmp - 1;
            else
                sum++;
        }
    }

    cout << sum;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, r=0;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    for(int i=0; i<n; i++)
    {
        if(arr[i]==1)
        {
            r = n-i;
            for(int j=i; j<n; j++)
            {
                if(arr[j]==0 && j+1 >= n)
                {
                    r--;
                }
                else if(arr[j]==0 && (arr[j+1]==0) )
                {
                    j++;
                    r-=2;
                }
            }
            break;
        }
    }

    cout<<r<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void fl() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
//	freopen("ot.txt", "w", stdout);
#else
//	freopen("jumping.in", "r", stdin);	// HERE
#endif
}
int i, j, k;
#define forr(i,j, n) for(i = j;i < n;i++)
#define in(n) scanf("%d",&n)	//scan int
#define ot(x) printf("%d", x)	//output int
////////////////////////////////////////////////////////////////////////////////////////////////
// snippet  ::  dinp , dhelp , dvec , lli , dfor , dcons , dbit
int main() { // dfil
	fl(); //TODO
	int n, res = 0;
	int p, bh = 0, ah = 0;
	in(n);
	forr(i, 0, n and in(p))
		if (!p and ah)
			continue;
		else if (!p and !bh)
			bh = 1, res++;
		else if (!p and bh)
			res = max(0, res - 1), bh = 0, ah = 1;
		else if (p)
			res++, bh = 0, ah = 0;
	ot((p or ah) ? res : res - 1);
	return 0;
}

#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define f(i, n) for (i = 0; i < n; i++)
#define F first
#define S second
#define pb push_back
#define pll pair<long long, long long>
#define vl vector<long>

int main() {
  fast
  int n, i, j, l=0, k, m = INT_MAX, o, p=-1, q, r, c1=0;
  cin>>n;
  int a[n];
  f(i,n){
      cin>>a[i];
      if(a[i] == 1){
          l=1;
          m = min(m,i);
          p = max(p,i);
      }
  }
  c1=p-m;
  c1++;
  if(l==0){
      cout<<"0";
      return 0;
  }
  f(i,n-2){
      if(i>m && i<p)
      if(a[i+1]==0 && a[i+2] == 0){
          c1-=2;
          i+=2;
      }
  }
  cout<<c1;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

/*ifstream in("input.txt");
ofstream out("output.txt");*/

int n;
vector <int> a;

int main()
{
	cin >> n;
	a.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int k = 0;
	int z = 0;
	for (int i = 0;i < n;i++) {
		if (a[i] == 1){
			k++;
			z = 0;
		}
		else if (k != 0 && a[i] == 0 && z >= 1)
			k++;
		else if (a[i] == 0)
			z++;
	}
	cout << k;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define GC getchar
#define PC putchar

#define FRE freopen("input.txt","r",stdin);

typedef long long int ll;

inline int ri()
{
    int n=0,a=1;
    char c=GC();

    while(c < 48 || c >57)
	{
		if(c=='-')
		{
			a=-1;
		}
		c=GC();
	}
    while(c>47 && c<58)
    {
   		n=(n<<3)+(n<<1)+c-'0';
    	c=GC();
    }
    return a*n;
}

inline void pi(ll a)
{
	char snum[40];
	int i=0;
	do
	{
		snum[i++]=a%10+48;
		a=a/10;
	}while(a!=0);

	i=i-1;

	while(i>=0)
		PC(snum[i--]);
	PC('\n');
}

int main()
{
	int i=0,n=ri(),count;

	int a[n];

	for(i=0;i<n;i++)
		a[i]=ri();

	for(i=n-1;i>=0;i--)
	{
		if(a[i]==0)
			n--;
		else
			break;
	}

	bool flag=true;

	count=n;
	//pi(count);
	for(i=0;i<n;i++)
	{
		if(flag)
		{
			if(a[i])
			{
				flag=false;
				count-=i;
			}
		}
		else
		{
			if(a[i-1]==0 && a[i]==0)
				count-=2;
		}
	}

	pi(count);

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, array[110];

    while(cin>>n)
    {
        int count = 0;

        for(int i = 0; i < n; i++)
        {
            cin>>array[i];
        }
        for(int i = 0; i < n; i++)
        {
            if(array[i] == 1 && array[i+1] == 0)
            {
                count++;
            }
            else if(array[i] == 0 && array[i+1] == 1)
            {
                continue;
            }
        }
        cout<<n-count<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> vec(n);
	for(int i=0;i<n;i++)
		cin>>vec[i];

	int j=0;
	while(vec[j]==0)
		j++;
	//cout<<j<<"\n";
	int cnt=0;
	while(j<n)
	{
		if(j == n-1)
		{
				if(vec[j]==0)
				break;
		}

		if(vec[j]==1)
		{
			cnt++;
			j++;
		}
		if(vec[j]==0 && j+1<n && vec[j+1]==0)
		{
			j+=2;
			continue;
		}
		else if(vec[j]==0 && j+1<n && vec[j+1] == 1)
		{
			cnt++;
			j++;
		}

	}

	cout<<cnt;
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int i, m, n, a,b;
    vector <int> v;

    while(cin>>n)
    {
        int cnt = 0;
        for(i=0; i<n; i++)
        {
            cin>>a;
            v.push_back(a);
        }
        for(i=0; i<v.size(); i++)
        {
            if(v[i]==1)
                cnt++;

            else if(v[i]==0 && v[i-1]!=0 && v[i+1]!=0)
                cnt++;
        }
        cout<<cnt<<endl;
        v.clear();
    }
    return 0;
}

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

int n, x, dem;
vector <int> vc;

int main() {

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> x;
        vc.push_back(x);
    }

    vc.push_back(0);

    for (int i = 0; i < n; ++i) {
        if (vc[i] == 1 || vc[i+1] == 1) ++dem;
        else {
            ++i;
        }
    }

    if (vc[0] == 1 && n == 1) dem = 1;

    cout << dem;

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100 + 5;
int n, a[MAXN];
long long ans = 0;

int main(){
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int ind = 0;
    for (int i = 0; i < n; i++){
        if (a[i] == 1){
            ind = i;
            i = n;
        }
    }

    for (int i = ind; i < n; i++){
        if (a[i] == 1)
            ans ++;
        else if (a[i] == 0){
            if (i + 1 < n && a[i + 1] == 0)
                i++;
            else if (i - 1 >= 0 && a[i - 1] == 1)
                ans++;
        }
        else
            ans ++;
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,nc=0,num,c=0,yes=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{cin>>num;
	if(num==0)
	 	{++nc;
	 	}
	 if(nc>1||(i==n-1&&num==0))
	 {break;
		 }
	if(num==1){yes=1;nc=0;
	}
	if(yes==1)++c;
	}
	cout<<c;
}

#include <bits/stdc++.h>

using namespace std;

int n, a[105], k, m;
bool l;

int main()
{
	cin >> n;
	m = n;
	for (int i = 0; i < n; i++)
	cin >> a[i];
	for (int i = 0; i < n; i++)
	if (a[i] == 0)
	k++;
	else break;
	if (k == 1)
	{
		m -= k;
		n--;
	}
	k = 0;
	for (int i = 0; i < n; i++)
	if (a[i] == 0)
	k++;
	else
	{
		if (k > 1)
		m -= k;
		k = 0;
		l = true;
	}
	m -= k;
	cout << m;
	return 0;
}

/* Copyright "hasanb" */
#include<bits/stdc++.h>

using namespace std;

#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define ci(x) cin >> x
#define co(x) cout << x << endl;
#define cii(x,y) cin >> x >> y;
#define coo(x,y) cout << x << ' ' << y << endl;
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define pts puts("")
#define endl '\n'
#define inf mod
int arr[N],n,ans,t,s;
int main(){
	cin >> n;
	FOR(i,1,n)
		cin >> arr[i];

	t=1;
	while(t<=n && !arr[t])
		arr[t]=1,ans++,t++;
	int t2=n;
	while(t2 > t+1 && !arr[t2])
		arr[t2]=1,ans++,t2--;

	for(int i=1;i<=n;i++){
		s=i;
		while(s<=n && !arr[s]){
			s++;

		}
		if(s-i>1){
			ans += s-i;
			i=s-1;
		}
	}

	cout << n-ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int c=0;
    for(int i=0;i<n-1;i++){
        if(a[i]==0 && a[i+1]==0){i++; continue;}
        else c++;
    }
    cout<<c;
    return 0;
}

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

int main()
{
	int t;
	cin >> t;
	int n[t];
	for(int i=0; i<t; ++i) cin >> n[i];
	if(t==1)
	{
		if(n[0]==1) cout << 1 << endl;
		else cout << 0 << endl;
	}
	else
	{
		for(int i=0; i<t-1; ++i)
		{
			if(n[i]==n[i+1])
			{
				cout << i+1 << endl;
				return 0;
			}
		}
		cout << 0 << endl;
		return 0;
	}
	return 0;
}

#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
using namespace std;
typedef long long int ll;
vector<int>v;
#define PI           3.14159265358979323846

int main()
{
    int n,a,b,ans,len,i,cnt;

    cin>>n;
    int arr[n+5];

    for(i=0;i<n;i++)
    {
         cin>>arr[i];
    }
    cnt = 0;
     for(i=0;i<n;i++)
     {
           if(arr[i]==1)
           {
              ans++;

               if(cnt<2)
               ans+=cnt;
               //cout<<ans<<" "<<cnt<<" "<<i<<endl;
               cnt = 0;
           }
           else
           {

                cnt++;
           }
     }
     cout<<ans<<endl;
}

#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int n;
    int num[100];
    while(scanf("%d",&n)!=EOF){
        int st = 0;
        for(int i = 0; i < n; i++){
            scanf("%d",&num[i]);
        }
        if(num[0]==0){
            st = 0;
        }else{
            st = 1;
        }
        for(int i = 1; i < n; i++){
            int j;
            if(num[i] == 0 &&(num[i-1]==0||num[i+1]==0)){
                j = 0;
            }else{
                j =1;
            }
            st = st+j;
        }
        printf("%d\n",st);
    }
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int k[n+2],ans=n;
    for(int i=0 ; i<n ; i++)
    {
        cin>>k[i];
        if(i==0 && k[i]==0)
        ans--;
        if(k[i]==0 && k[i-1]==0)
        {
            if(k[i-2]==0)
            ans--;
            else
            ans-=2;
        }
    }
    if(k[n-1]==0 && n>1)
    ans--;
    cout<<ans;
    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int n,a[101],s2=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		if (a[i]==1||(a[i-2]==1&&a[i]==1&&a[i-1]==0)) s2++;
	}
	cout<<s2;
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int n ;
    cin>>n;
    int  arr[n];
    int c=0,c0=0;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    for(int i=0;i<n;i++)
    {
        if (arr[i]==1)
        {
            c++;
            c0=0;
        }
        else if(arr[i]!=arr[i+1]&&c>0&&c0==0)
            c++;
        else if(arr[i]==arr[i+1]&&arr[i]==0)
        {
            i++;
            c0++;
        }
    }
    cout<<c<<endl;

	return 0;
}

#include <ios>
#include <iostream>

int arr[105] = {};

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n, k, j, ans;
	std::cin >> n;
	for (int i = 0; i < n; i++) std::cin >> arr[i];
	k = -1;
	j = -1;
	for (int i = n-1; i >= 0; i--)
	{
		if (arr[i])
		{
			k = i;
			break;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (arr[j])
		{
			j = i;
			break;
		}
	}
	k++;
	j++;
	ans = 0;
	for (int i = j; i < k; i++)
	{
		if (i != k-1 && arr[i] == 0 && arr[i+1] == 0);
		else if (i != j && arr[i] == 0 && arr[i-1] == 0);
		else ans++;
	}
	std::cout << ans << '\n';
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

/*auto check(int n)
{

}*/

int main()
{
	int n ;
	cin>>n;
	std::vector<int> v;
	for (int i = 0; i < n; ++i)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	int j=n-1,k=0,count = 0,y=0,t=0;
	while(j>=0)
	{
		if(v[j]==1)
		{
			t=j;
			break;
		}
		j--;
	}
	while(k<n)
	{
		if(v[k]==1)
		{
			y=k;
			break;
		}
		k++;
	}

	for (int i = y; i <= t-1; ++i)
	{

		if(!(v[i]==0 && v[i+1]==0))
			{count++;}
		else
			i++;
	}
	if(!(y==t && v[y]==0))
		cout<<count+1;
	else
		cout<<"0";
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define endl '\n'
#define llint long long int
#define vint vector<int>
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int ans, a, n, count, z_c, start;
    bool st, flg;
    count = 0;
    z_c = 0;
    a = 0;
    cin >> n;
    for(start = 0 ; start < n ; ++start){
    	cin >> a;
    	if(a == 1)
    		break;
	}

	for(int i = start ; i < n ; i++){
			if(!st){
				st = true;
			}
			else{
				cin >> a;
			}
			if(a == 1){
				count++;
				if(z_c < 2){
					count += z_c;
				}
				z_c = 0;
			}
			if(a == 0){
				z_c++;
				//z_buff++;
			}
	}
    cout << count;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;
int arr[n];
int e=0;
for(int i=0;i<n;i++)
    cin>>arr[i];
for(int i=0;i<n;i++)
{
    if(arr[i]==0&&arr[i+1]==0){
        e+=2;
        i++;
    }
}
int sum=n-1-e;
if(sum<0){
    cout<<0;
}
else
    cout<<sum;
    return 0;
}

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,n,m,i,j,t,d,c;
    int arr[100000];
    scanf("%d",&n);
    c=0;
    d=n;
    m=1;

    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);

    }
    if(arr[1]==0&&arr[2]==1)
    {
        d=d-1;
    }
    int f=1;
    for(i=1;i<=n;i++)
    {
        if(arr[i]==0)
        {
            c++;
        }
        else
        {
            f=0;
            if(c>=2)
            {
               d=d-c;
            }
            c=0;
        }
    }
    if(arr[n]==0&&arr[n-1]==1)
    {
        d=d-1;
    }
    if(f==0)
    printf("%d\n",d);
    else
        printf("%d",d-c);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 1<<30;

int main()
{
    int n;
    scanf("%d",&n);
    int a[110];
    for(int i=1;i<=n;++i) scanf("%d",a+i);
    int ans=0;
    int pre=0;
    for(int i=1;i<=n;++i) {
        if(a[i]) {
            if(i-pre<=2 && pre != 0) a[i-1]=1;
            pre=i;
        }
    }
    for(int i=1;i<=n;++i) {
        cout<<a[i]<<' ';
        if(a[i]) {
            ans+=1;
        }
    }
    cout<<endl;
    printf("%d\n",ans);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define ll long long int
#define print(a) cout<<a
#define T ll t; cin>>t ; while(t--)
#define fin freopen("input.txt","r",stdin)
#define fout freopen("op.txt","w",stdout)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define debug(s,n) cout<<">> "<<s<<" : "<<n<<endl
#define pf(n) cout<<n<<" "

int main(){
    fastio;

    ll n;
    cin>>n;

    ll a[n+10];

    for(ll i=0;i<n ;i++)
        cin>>a[i];

    ll ans=n;
    ll f=0,l=n-1;

    while(a[f]==0 && f<n) {
        f++;
        ans--;
    }

    while(a[l]==0 && l>=0){
        l--;
        ans--;
    }

    for(ll i=f+1;i<l;i++) {
        if(a[i]==0) {
            if(a[i+1]==0) {
                ans-=2;
                i+=2;
            }
        }
    }

    pf(ans);

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100 + 5;
int n, a[MAXN];
long long ans = 0;

int main(){
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int ind = 0;
    for (int i = 0; i < n; i++){
        if (a[i] == 1){
            ind = i;
            i = n;
        }
    }
    int tah = n - 1;
    for (int i = n - 1; i >= 0; i--){
        if (a[i] == 1){
            tah = i;
            i = 0;
        }
    }

    for (int i = ind; i <= tah; i++){
        if (a[i] == 1)
            ans ++;
        else if (a[i] == 0){
            cout << i << " ";
            if (i + 1 < n && a[i + 1] == 0)
                i++;
            else if (i - 1 >= 0 && a[i - 1] == 1)
                ans++;
            cout << i << endl;
        }
        else
            ans ++;
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
    int vec[150];
    int n,c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&vec[i]);
    for(int i=0;i<n;i++) {
        if(n==1)
          { (vec[i]) ? c=0 : c=1; break; }
        if(vec[i]==0 && i==0 || vec[i]==0 && i==n-1)
            c++;
        else if(vec[i]==0 && vec[i+1]==0)
            c+=2;
    }
    if(n-c<0)
        printf("0");
    else
        printf("%d",n-c);
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#include <cstring>

using namespace std;

//#define int long long
#define MAX 100005
#define INF 0x3f3f3f3f
#define rep(i,n) for(int i = 1; i <= n; (i)++)
#define For(i,a,b) for(int i = a; i <= (b); (i++))
#define mid ((l + r) >> 1)
#define lson (p<<1)
#define debug cout  << "!!!" << endl;
//#define cin in
typedef pair<int,int> P;

int arr[MAX];
signed main(void)
{
   int n; cin >> n;
   for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);
   int l = 1, r = 2;
   int an = 0;
   while(l <= n){
        while(arr[l] == 0)l++;
        while(r <= n && !(arr[r] == 0 && arr[r-1] == 0))r++;
        an = max(an,r - l);
        l = r;
        r = l + 1;
   }
   cout << an << endl;
   return 0;
}
/*
16 16 1 16
3 2 2 2 3 2 2 2 3 2 2 1 3 2 2 1
*/

#include<iostream>
using namespace std;

int main()
{
int n,vr;
cin >> n;
vr = n;
bool a[n];
for(int i = 0;i < n;i++)
  cin >> a[i];

if((a[n-1]==0)&&(a[n-2]==1))
   vr--;
if((a[0]==0)&&(a[1]==1))
   vr--;
for(int i = 0;i < n;i++)
  {
    if ((a[i]==0)&&(a[i+1]==0))
     vr--;
  }
  cout << vr <<endl ;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

//////////////////////////////////////////////////////////////////////////////////
    #define endl '\n'
    #define ll long long
    #define pb push_back
    #define mt make_tuple
    #define in(a) for (auto& i: a)
    #define ull unsigned long long
    #define tbeg clock_t tvar=clock();
    #define test ull t; cin >> t; for (ull tc=1; tc<=t; tc++) {
    #define tend cout << "\n\nTime: " << (double)(clock()-tvar)/CLOCKS_PER_SEC;
//////////////////////////////////////////////////////////////////////////////////

int main()
{

    ll n, i, count=0, end;
    cin >> n;
    end=n;
    ll a[n];
    for (i=0; i<n; i++)
    {
        cin >> a[i];
        if (a[i]==0) end=min(i, end);
        else end=n;
    }

    for (i=0; i<n && a[i]==0; i++);
    for (; i<end; i++)
    {
        if (a[i]==0 && a[i+1]==0) { i++; continue; }
        count++;
    }
    cout << count;

}

#include <iostream>
using namespace std;
int main()
{
int a,b,k,l; l = 0;
cin >> k;
cin >> a;
while ((a==0)||(k!=0))
{cin >>a;
 k--;
}
if ((k == 0)&&(a==0))
{cout << 0;
return 0; }
if ((k==0)&&(a==1))
{cout << 1;
return 0;
}
for (int i =0; i<k; i++)
{
cin >> b;
if (a||b) l++;
a=b;
}
cout<< l;
return 0;
}

#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;
int arr[n];
int e=0;
int index=-1;
for(int i=0;i<n;i++)
    cin>>arr[i];
bool b=true;
int index_2=0;
for(int i=0;i<n;i++)
{
    if(arr[i]==1&&b){
        index=i;
        b=false;
     //   break;
    }
    if(arr[i]==1){
        index_2=i;
    }
}
for(int i=index;i<=index_2;i++)
{
  if(arr[i]==0&&arr[i+1]==0){
    i++;
   //cout<<e<<endl;
    continue;
  }
  else
    e++;

}
if(index!=-1)
cout<<e;
else{
    cout<<0;
}
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 110;
int num[maxn];
int main()
{
    int n;
    cin >>n;
    int count = 0;
    int p;
    bool flag = true;
    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
        if (num[i] != 0&&flag)
        {
            p = i;
            flag = false;
        }
    }
    if (flag)
        cout << 0 << endl;
    else
    {
        for (int i = p; i < n; i++)
        {
            if (num[i] == 1)
            {
                count++;
            }
            else
            {
                if (num[i + 1] != 0)
                    count++;
                else
                    i++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
      cin>>arr[i];
  }
  if(n==1 && arr[0]==0){
      cout<<"0";
      return 0;
  }
  int b=n;
  int i=0;
  int z=n-1;
  while(arr[i]==0){
      b--;
      i++;
  }
  while(arr[z]==0){
      b--;
      z--;

  }
  for(int j=i;j<=z;j++){
      if(arr[j]==0&&arr[j+1]==0){
          b-=2;
      }

  }

cout<<b;

    return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int a,b=0,c=0,sum=0;
    cin>>a;
    bool s[a];
    for(int i=0;i<a;i++)
        cin>>s[i];
        for(int q=0;q<a;q++)
        {
            if(s[q]==1)
            {
                b=q;
                break;
            }
        }
        for(int m=a-1;m>=0;m--)
        {
            if(s[m]==1)
            {
               c=m;
               break;
            }
        }
        for(int w=b;w<=c;w++)
        {
            if(s[w]==0 && s[w-1]==0)
                sum--;
            else
                sum++;
        }
        if(b==0 && c==0)
            sum=0;
        cout<<sum;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, array[110];

    while(cin>>n)
    {
        int count = 0;

        for(int i = 0; i < n; i++)
        {
            cin>>array[i];
        }
        for(int i = 0; i < n; i++)
        {
            if(array[i] == 1 && array[i+1] == 0)
            {
                count++;
            }
            else if(array[i] == 0 && array[i+1] == 1)
            {
                continue;
            }
        }
        cout<<n-count<<endl;
    }
    return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n;
	int *a;
	cin >> n;
	a = new int[n];
	int startCounter = 0, endCounter = 0, counter = 0, totalLength = n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	while (a[startCounter] == 0)
	{
		startCounter++;
	}

	while (a[n - 1 - endCounter] == 0)
	{
		endCounter++;
	}
	if (totalLength - startCounter != totalLength - endCounter)
		totalLength -= (startCounter + endCounter);
	else totalLength = 0;

	for (int i = startCounter; i < n - endCounter; i++)
	{
		if (a[i] == 0)
			counter++;
		if (a[i] == 1 && counter < 2)
                    counter = 0;
		if (counter >= 2 && a[i] == 1)
		{
			totalLength -= counter;
			counter = 0;
		}
	}
	totalLength -= counter;
	cout << totalLength;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
    int vec[150];
    int n,c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&vec[i]);
    for(int i=0;i<n;i++) {
        if(n==1)
          { (vec[i]) ? c=0 : c=1; break; }
        if(vec[i]==0 && i==0 || vec[i]==0 && i==n-1)
            c++;
        else if(vec[i]==0 && vec[i+1]==0)
            c+=2;
    }
    printf("%d",n-c);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, array[110];

    while(cin>>n)
    {
        int count = 0;

        for(int i = 0; i < n; i++)
        {
            cin>>array[i];
        }
        if(n == 1)
            cout<<"0"<<endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                if(array[i] == 1 && array[i+1] == 0)
                {
                    count++;
                    i++;
                }
                else if(array[i] == 0 && array[i+1] == 1)
                {
                    continue;
                }
            }
            if(count >= 1)
            {
                cout<<n-count<<endl;
            }
            else
            {
                cout<<count<<endl;
            }
        }
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;

int main() {
	int n;
cin>>n;
	int arr[n];
	int qe = 0;
	for (int i =0 ; i < n;i++) {
		cin>>arr[i];
	}

	int summa  = 0 ;
	if (n==1 && arr[0]!=0) n++;
	for (int i =0 ; i < n-1;i++) {
		if (arr[i]==0 && arr[i+1]==0) {
			qe+=2;
			i+=1;

		}
		else if (arr[i]==0 && arr[i+1]==1  )
		{
			summa++;
			//cout<<"YES";
			continue;
		}
		else if (arr[i]==1 && arr[i+1]==0  ) {
			summa++;
			//cout<<"DA";
			continue;
		}
		else if (arr[i]==1) {
			summa++;
		}

	}
	cout<<summa;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=101;
int a[maxn];
int main()
{
    int n;
    while(cin>>n)
    {
        memset(a,-1,sizeof(a));
        for(int i=0;i<n;i++)
        cin>>a[i];
        int cnt=0;
        if(a[0]==1)
        cnt=1;
        else
        cnt=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]==1)
            cnt++;
            else if(a[i]==0)
            {
                if(a[i+1]==1)
                cnt++;
                else
                {
                    i++;
                }
            }
        }
        cout<<cnt<<endl;
    }
}

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
ifstream fin("input.txt");
ofstream fout("output.txt");

int n,answ=0;
fin >> n;
int ni=1,li=1;
bool u=false;
for(int i=0; i<n; ++i)
{

    int g;
    fin >> g;

    li=ni;
    ni=g;
    if(g==1)
        u=true;
    if(u==false)
        ++answ;
    if(li==0 && ni==0)
    {
        answ=answ+2;
    }
    else
    {
        if(g==0 && i==n-1)
            ++answ;
    }

}
fout << n-answ;
return 0;
}

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;
long long modNew=1e9+6;

#define llu long long unsigned
#define lld long long
#define ld long
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 1000003
#define lim2 3003
 lld A[lim],C[lim],B[lim];
 // char C[lim2][lim2];
 //string A,B;
// char S[lim];
// map<lld,lld> M;
// map<lld,lld>::iterator it;
// map<string,lld> M,Mn;
// string S[lim];

// multiset<lld> S;
//vector<lld> A[400];
// set<lld> S;
// string S;
// lld A[10003][12];
// vector<lld> V[lim],ANS;

// lld A[53][53],C[53][53],dp[53][53];

int main(){
    lld T,i,j,k,l,r,s,a,b,c,d,w,x,y,v,z,m,n,t,p,q,curr,sum,ans,pos,val,countA,secondMin;
    sc(n);
    countA=0;
    a=b=0;
    for(i=1;i<=n;i++){
        sc(A[i]);
    }
    for(i=1;i<=n;i++){
        if(A[i]==1){
            a=i;
            break;
        }
    }
    for(i=n;i>=1;i--){
        if(A[i]==1){
            b=i;
            break;
        }
    }
    countA=b-a+1;
    for(i=a+1;i<=b;i++){
        if(A[i]==0 && A[i-1]==0){
            countA-=2;
            i++;
        }
    }
    prL(countA);
    return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
 int n, k=0, a=0;
 cin>>n;
 for (int i=1;i<=n;i++)
 {
     cin>>a;
     if (a%2!=0) k+=1;
 }
 if (n>2 and k>0) k+=1;
 cout<<k;
    return 0;
}

#include<bits/stdc++.h>
#define ll long
using namespace std;
int main()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int i=0,ans=0;
   while(i==0 && i<n)
    i++;
   while(i<n){
    if(a[i]==1){
        ans++;
        i++;
    }

    else{
            int zero=0;
        while(a[i]==0){
            i++;
            zero++;
        }
        if(zero==1)
            ans++;
    }
   }
   cout<<ans;
   return 0;
}

#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<math.h>
#include<algorithm>

using namespace std;

main()
{
	int n, m=0, i, k, x, y, z=0;
	cin>>n;
	int a[n];
	for (i=0; i<n; i++){
		cin>>a[i];
	}
		if (a[0]=0){
			if (n=1){
				m=0;
			}
			else {

		while (a[z]=0)
		{
			z=z+1;

		}
	}
}

		{
	for (k=z; k<n; k++){

		if (a[k]=1)
			{

				m++;
				k++;

			}
			else {
				if(a[k+1]=1)
				m++;
				k++;
			}

	}

	cout<<m;

}
}

/*
* @Author: Krishna
* @Date:   2015-12-23 19:27:14
* @Last Modified by:   Krishna
* @Last Modified time: 2015-12-23 19:51:02
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <set>
#include <omp.h>
#include <cstring>
#include <map>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define loop(i,x,y) for(int i = x; i < y; ++i)

using namespace std;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<int,int>::iterator miit;
int max (int a, int b) { return a > b ? a : b;}
int min (int a, int b) { return a < b ? a : b;}
int gcd(int a, int b){ return (b==0)? a : gcd(b, a%b);}

int main() {
	int n;
	cin >> n;
	int a[n];
	rep(i,n) cin >> a[i];
	int pairs = n;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		int x = a[i];
		if(x == 0 && i == 0) pairs--;
		else if(x == 0) cnt++;
		else {
			if(cnt >= 2)
				pairs -= cnt;
			else if(i + 1 != n)
				cnt = 0;
		}
	}
	printf("%d\n",pairs-cnt);
	//system("pause");
	return 0;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<ctime>
#include<bitset>
#define LL long long
#define db double
#define EPS 1e-15
#define inf 1e10
#define pa pair<int,int>

using namespace std;

int a[105],ans,n;
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for (int i=1;i<=n-2;i++) {
        if (a[i]==1) {
            ans++;
        }else if (a[i+2]==1){
            ans++;
        }
    }
    if (a[n-1]==1) ans++;
    if (a[n]==1) ans++;
    printf("%d\n",ans);
    return 0;
}

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include<algorithm>

#define fi first
#define se second

typedef long long ll;

using namespace std;

    const int maxn=(int)3e5+10;
    const int inf=(int)1e9+5;
    const ll llinf=(ll)1e18+5;

    ll a[maxn];
    ll b,c,d,i,n,k,l,p;
int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
          cin>>n; ll sum=0; p=-100;
                for(i=0;i<n;i++){
                    cin>>a[i];
                        if (a[i]==1){
                            sum+=1;
                            if (p==-100){
                                p=i;
                            }
                        }
                }
                        ll tiwe=1;
                        if (p!=0){
                            for(i=p;i<n;i++){

                                if ((a[i]!=a[i+1])and(a[i]==0)){
                                    if (tiwe<2){
                                        sum+=1;
                                        tiwe=1;
                                    }
                                }
                                else if (a[i]==a[i+1])
                                        tiwe++;
                            }
                        }
                        else
                        {
                                    for(i=0;i<n;i++){

                                        if ((a[i]!=a[i+1])and(a[i]==0)){
                                            if (tiwe<2){
                                                sum+=1;
                                                tiwe=1;
                                            }
                                        }
                                        else if ((a[i]==a[i+1])and(a[i]==0))
                                            tiwe++;
                                    }
                        }
            cout<<sum<<endl;

    return 0;
}