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