#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

char c[567890];
int a[567890], dp[567890];
int n;

int main() 
{
	scanf("%d%s", &n, c+1);
	
	for (int i=1;i<=n;++i) 
	{
		if (c[i]=='0') a[i]=i;
		else a[i]=a[i-1];
	}
	
	for (int i=1;i<=n;++i) 
	{
		dp[i] = dp[i-1];
		if (c[i]=='1') 
		{
			if (c[i-1]=='0'&&c[i-2]=='1') 
			{
				dp[i]=max(dp[i],dp[a[i-2]]+(i-2)-a[i-2]);
				dp[i]=max(dp[i],dp[a[i-2]+1]+(i-2)-(a[i-2]+1));
			}
			else if (a[i]>1&&c[a[i]-1]=='1') dp[i]=max(dp[i],dp[a[i]-2]+i-a[i]);
		}
	}
	
	cout<<dp[n];
	
	return 0;
}