//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;;
char s[500008];int nxt[500008];int n; int dp[500008];int op;
int main()
{
	cin>>n;scanf("%s",&s);nxt[n]=n;
	for(int i=n-1;i>=0;i--)
	{
		nxt[i]=nxt[i+1];if(s[i]=='0') nxt[i]=i;else op++;
	}
	for(int i=0;i<=n;i++) dp[i]=n+233;dp[0]=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='0')
		{
			dp[i+1]=min(dp[i],dp[i+1]);
			continue;
		}
		dp[i+1]=min(dp[i]+1,dp[i+1]);
		if(s[i+1]=='0')
		{
			for(int j=i+2;j<n;j++)
			{
				if(s[j]=='0')
				{
					break;
				}
				dp[j+1]=min(dp[i]+1,dp[j+1]);
			}
		}
		else
		{
			if(s[nxt[i]+1]=='1')dp[nxt[i]+1+1]=min(dp[i]+1,dp[nxt[i]+1+1]);
		}
	}
	cout<<op-dp[n];
	return 0;
}