#include<iostream>
#include<cstdio>
#define maxn 500010
using namespace std;
char s[maxn];
int n;
int place[maxn],dp[maxn];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='0')
			place[i]=i;
		else
			place[i]=place[i-1];
	}
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if(s[i]=='1')
		{
			if(s[i-1]=='0'&&s[i-2]=='1')
			{
				dp[i]=max(dp[i],dp[place[i-2]]+(i-2)-place[i-2]);
				dp[i]=max(dp[i],dp[place[i-2]+1]+(i-2)-place[i-2]-1);
			}
			else if(place[i]>1&&s[place[i]-1]=='1')
				dp[i]=max(dp[i],dp[place[i]-2]+i-place[i]);
		}
	}
	printf("%d\n", dp[n]);
	return 0;
}