#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
using namespace std;

const int Maxn = 500005;

int n;
string s;
int l[Maxn],r[Maxn];
int dp[Maxn];
vector<int> pre[Maxn];

int main(){
	scanf("%d",&n);
	cin>>s;
	int x=-1,y=0;
	memset(l,0,sizeof l);
	memset(r,0,sizeof r);
	while(y<n){
		int count = 0;
		while(y<n && s[y]=='1') y++,count++;
		if(y<n) l[y]=count;
		if(x>0) r[x]=count;
		x=y;
		y++;
	}
	for(int i=0;i<n;i++){
		if(s[i]=='0'&&s[i-1]=='1'&&s[i+1]=='1'){
			for(int j=1;j<=l[i];j++){
				pre[i+1].push_back(i-j);
			}
			for(int j=1;j<=r[i];j++){
				pre[i+j].push_back(i-1);
			}
		}
	}
	for(int i=0;i<n;i++){
		dp[i]=max(dp[i],dp[i-1]);
		for(auto v:pre[i]){
			dp[i]=max(dp[i],dp[v-1]+(i-v-1));
		}
	}
	printf("%d\n",dp[n-1]);
return 0;
}