#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MaxN = 5e5;
using namespace std;
int pre[MaxN + 5][3], a[MaxN + 5], last[MaxN + 5];
int dp[MaxN + 5];
char s[MaxN + 5];
int n;
int main()
{
	while(~scanf("%d", &n)) {
		scanf("%s", s + 1);
		for (int i = 1; i <= n; i++) {
			a[i] = s[i] - '0';
			pre[i][0] = last[0];
			last[a[i]] = i;
		}
		for (int i = 0; i <= n; i++) dp[i] = -(1 << 30);
		dp[0] = 0;
		for (int i = 1; i <= n; i++) {
			dp[i] = dp[i - 1];
			if(!a[i]) continue;
			if(a[i - 2] && !a[i - 1] && a[i]) {
				int l = pre[i - 2][0];
				dp[i] = max(dp[i], dp[l] + i - l - 2);
				dp[i] = max(dp[i], dp[l + 1] + i - l - 3);
			}
			int k = pre[i][0];
			if(k >= 2 && a[k - 1]) {
				dp[i] = max(dp[i], dp[k - 2] + i - k);
			}
		}
		printf("%d\n", dp[n]);
	}
}