#include <bits/stdc++.h>
using namespace std;
const int maxn=500005;
int n,dp[maxn],pre;
char s[maxn];
int main()
{
    scanf("%d%s",&n,s+1);
    for (int i=2;i<n;++i) {
        dp[i+1]=dp[i];
        if (s[i]=='0'&&s[i-1]=='1'&&s[i+1]=='1') {
            pre=i+1;
            for (int j=i-1;j>=1&&s[j]=='1';--j)
                dp[i+1]=max(dp[i+1],dp[j-1]+i-j);
        }
        if (s[i+1]=='0')
            pre=0;
        if (pre)
            dp[i+1]=max(dp[i+1],dp[pre-3]+i-pre+2);
    }
    printf("%d\n",dp[n]);
    return 0;
}
