#include <bits/stdc++.h>
using namespace std;
const int MAX_N=500005;
char str[MAX_N];
int dp[MAX_N],L[MAX_N];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",str+1); 
    for(int i=1;i<=n;i++)
    {
        if(str[i]=='1')L[i]=L[i-1];
        else L[i]=i;
    }
    for(int i=1;i<=n;i++)
    {
        dp[i]=dp[i-1];
        if(str[i]=='1')
        {
            if(str[i-1]=='0' && str[i-2]=='1')
            {
                dp[i]=max(dp[i],dp[L[i-2]]+(i-2)-L[i-2]);
                dp[i]=max(dp[i],dp[L[i-2]+1]+(i-2)-L[i-2]-1);
            }
            else if(L[i]>1 && str[L[i]-1]=='1')
            {
                dp[i]=max(dp[i],dp[L[i]-2]+i-L[i]);
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}