#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+1;

int n, pre[N], nxt[N], dp[N];
string s;
bool a[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> s;
	for(int i = 0; i < n; i++) a[i] = s[i] - '0';
	for(int i = 0, curr = -1; i < n; i++) {
		if(!a[i]) curr = i;
		pre[i] = curr;
	}
	for(int i = n-1, curr = n; i >= 0; i--) {
		if(!a[i]) curr = i;
		nxt[i] = curr;
	}
	for(int i = 0; i < n; i++) {
		dp[i+1] = max(dp[i], dp[i+1]);
		if(a[i] && pre[i] != -1 && a[pre[i]-1]) dp[i+1] = max(dp[pre[i]-1] + i - pre[i], dp[i+1]);
		if(a[i] && nxt[i] < n-1 && a[nxt[i]+1]) dp[nxt[i]+2] = max(dp[i] + nxt[i] - i, dp[nxt[i]+2]);
	}
	cout << dp[n];
}
