#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int n,p,f[500010],c[500010],a[500010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%1d",&c[i]);
        if(!c[i])
            p=i;
        a[i]=p;
    }
    for(int i=1;i<=n;i++){
        f[i]=f[i-1];
        if(!c[i])
            continue;
        if(!c[i-1]&&c[i-2]){
            f[i]=max(f[i],f[a[i-2]]+i-2-a[i-2]);
        	f[i]=max(f[i],f[a[i-2]+1]+i-2-a[i-2]-1);
        }
        else if(a[i]>1&&c[a[i]-1])
            f[i]=max(f[i],f[a[i]-2]+i-a[i]);
    }
    printf("%d\n",f[n]);
    return 0;
}