#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Maxn = 500005;
const int Maxm = 4;
const int Inf = 1000000000;

int n;
char S[Maxn];
int dp[Maxn][Maxm][Maxm];

int main()
{
	scanf("%d", &n);
	scanf("%s", S);
	S[n] = S[n + 1] = '0'; 
	fill((int*)dp, (int*)dp + Maxn * Maxm * Maxm, -Inf);
	dp[n][0][0] = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < Maxm; j++) {
			int give = (j & 1) << 1 | int(S[i + 2] == '1');
			for (int k = 0; k < Maxm; k++) {
				int ret = (j & 2) | (k & 2) >> 1;
				dp[i][j][ret] = max(dp[i][j][ret], dp[i + 1][give][k]);
			}
			if (j & 2) dp[i][j][1] = max(dp[i][j][1], dp[i + 1][give][1] + 1);
		}
		if (S[i + 2] == '1')
			for (int k = 0; k < Maxm; k++) {
				int ret = (k & 2) >> 1;
				dp[i][2][ret] = max(dp[i][2][ret], dp[i + 1][2][k] + 1);
			}
	}
	int mask = int(S[0] == '1') << 1 | int(S[1] == '1');
	int res = 0;
	for (int j = 0; j < Maxm; j++)
		res = max(res, dp[0][mask][j]);
	printf("%d\n", res);
	return 0;
}