#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int n;
char a[1000009];
struct A{
int l,r,d;
bool operator<(const A& rhs)const{
if(l-rhs.l)return l>rhs.l;
return d>rhs.d;
}
};
int main(){
int i,j,k;
scanf("%d",&n);
scanf("%s",a);
int res=0;
int ll=0;
priority_queue<A> tq;
for(i=0;i<n;){
if(a[i]=='1'){
i++;
continue;
}
for(j=i;j<n;j++){
if(a[j]=='1')break;
}
int l,r,d;
d=(j-i)<<1;
l=((j+1)&(-2))-d;
if(l<0)l=0;
r=i&(-2);
tq.push({l,r,d});
i=j;
}
while(ll<n&&!tq.empty()){
A tt=tq.top();
tq.pop();
printf("%d %d %d , %d %d\n",tt.l,tt.r,tt.d,ll,res);
int tl=ll;
if(ll>tt.l){
if(ll<=tt.r){
tq.push({ll,tt.r,tt.d});
}
else{
tl=tt.r+tt.d;
if(ll<tl)ll=tl;
}
continue;
}
if(ll<tt.l){
res+=(tt.l-ll);
tl=tt.l;
}
if(tl>tt.r)tl=tt.r;
tl+=tt.d;
if(ll<tl){
ll=tl;
}
}
if(ll<n){
res+=(n-ll);
}
printf("%d\n",res>>1);
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxxdWV1ZT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG47CmNoYXIgYVsxMDAwMDA5XTsKc3RydWN0IEF7CiAgICBpbnQgbCxyLGQ7CiAgICBib29sIG9wZXJhdG9yPChjb25zdCBBJiByaHMpY29uc3R7CiAgICAgICAgaWYobC1yaHMubClyZXR1cm4gbD5yaHMubDsKICAgICAgICByZXR1cm4gZD5yaHMuZDsKICAgIH0KfTsKaW50IG1haW4oKXsKICAgIGludCBpLGosazsKICAgIHNjYW5mKCIlZCIsJm4pOwogICAgc2NhbmYoIiVzIixhKTsKICAgIGludCByZXM9MDsKICAgIGludCBsbD0wOwogICAgcHJpb3JpdHlfcXVldWU8QT4gdHE7CiAgICBmb3IoaT0wO2k8bjspewogICAgICAgIGlmKGFbaV09PScxJyl7CiAgICAgICAgICAgIGkrKzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGZvcihqPWk7ajxuO2orKyl7CiAgICAgICAgICAgIGlmKGFbal09PScxJylicmVhazsKICAgICAgICB9CiAgICAgICAgaW50IGwscixkOwogICAgICAgIGQ9KGotaSk8PDE7CiAgICAgICAgbD0oKGorMSkmKC0yKSktZDsKICAgICAgICBpZihsPDApbD0wOwogICAgICAgIHI9aSYoLTIpOwogICAgICAgIHRxLnB1c2goe2wscixkfSk7CiAgICAgICAgaT1qOwogICAgfQogICAgd2hpbGUobGw8biYmIXRxLmVtcHR5KCkpewogICAgICAgIEEgdHQ9dHEudG9wKCk7CiAgICAgICAgdHEucG9wKCk7CgogICAgICAgIHByaW50ZigiJWQgJWQgJWQgLCAlZCAlZFxuIix0dC5sLHR0LnIsdHQuZCxsbCxyZXMpOwogICAgICAgIGludCB0bD1sbDsKICAgICAgICBpZihsbD50dC5sKXsKICAgICAgICAgICAgaWYobGw8PXR0LnIpewogICAgICAgICAgICAgICAgdHEucHVzaCh7bGwsdHQucix0dC5kfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIHRsPXR0LnIrdHQuZDsKICAgICAgICAgICAgICAgIGlmKGxsPHRsKWxsPXRsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZihsbDx0dC5sKXsKICAgICAgICAgICAgcmVzKz0odHQubC1sbCk7CiAgICAgICAgICAgIHRsPXR0Lmw7CiAgICAgICAgfQogICAgICAgIGlmKHRsPnR0LnIpdGw9dHQucjsKICAgICAgICB0bCs9dHQuZDsKICAgICAgICBpZihsbDx0bCl7CiAgICAgICAgICAgIGxsPXRsOwogICAgICAgIH0KICAgIH0KICAgIGlmKGxsPG4pewogICAgICAgIHJlcys9KG4tbGwpOwogICAgfQogICAgcHJpbnRmKCIlZFxuIixyZXM+PjEpOwp9