#include<bits/stdc++.h>

using namespace std;
#define LL long long
#define mst(a, b)	memset(a, b, sizeof a)
#define pill pair<int, int>
#define mk make_pair
const int qq = 5e5 + 10;
int n;
char st[qq];
int dp[qq];

int main() {
	scanf("%d%s", &n, st + 1);
	int f = -1;
	for(int i = 3; i <= n; ++i) {
		dp[i] = dp[i - 1];
		if(st[i] == '1'&& st[i - 1] == '0' && st[i - 2] == '1') {
			f = i;
			for(int j = i - 2; st[j] == '1' && j >= 1; --j) {
				dp[i] = max(dp[i], dp[j - 1] + i - j - 1);
			}
		}
		if(st[i] == '0')	f = -1;
		if(st[i] == '1' && f != -1) {
			dp[i] = max(dp[i], dp[f - 3] + i - f + 1);
		}
	}
	printf("%d\n", dp[n]);
}