#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1234567;
char s[MAXN];
int f[MAXN];
int nxt[MAXN],prv[MAXN];
int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    memset(f,0,sizeof(f));
    nxt[n] = n;
    for(int i = n-1; i >= 0; --i)
    {
        if(s[i] == '0')
            nxt[i] = i;
        else
            nxt[i] = nxt[i+1];
    }
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == '0')
            prv[i] = i;
        else
            prv[i] = (i==0?-1:prv[i-1]);
    }
    for(int i = 0; i  <= n; ++i)
    {
        if(i >= 3 && s[i-1] == '1' && s[i-2] == '0' && s[i-3] == '1')
        {
            int j = prv[i-3];
            f[i] = max(f[i],f[j+1]+(i-j-3));
            if(j != i-4)
                f[i] = max(f[i],f[j+2]+(i-j-4));
        }
        if(i == n)
            break;
        if(i+3 <= n && s[i] == '1' && s[i+1] == '0' && s[i+2] == '1')
        {
            int j = nxt[i+2];
            f[j] = max(f[j],f[i]+(j-i-2));
            if(j != i+3)
                f[j-1] = max(f[j-1],f[i]+(j-i-3));
        }
        f[i+1] = max(f[i+1],f[i]);
    }
    printf("%d\n",f[n]);
    return 0;
}