#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int MAX = 5e5 + 5;
vector<ii> ranges[MAX];
int dp[MAX];
char str[MAX];

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", str);
	
	fori(i, 1, n - 1) {
		if(str[i] == '0' && str[i - 1] == '1' && str[i + 1] == '1') {
			int k = i - 1;
			int ones = 0;
			while(k >= 0 && str[k] == '1') {
				ones++;
				ranges[k].emplace_back(i + 1, ones);
				k--;
			}
			k = i + 1;
			ones = 0;
			while(k < n && str[k] == '1') {
				ones++;
				ranges[i - 1].emplace_back(k, ones);
				k++;
			}
		}
	}

	fori(i, 0, n) {
		if(i) {
			dp[i] = max(dp[i], dp[i - 1]);
		}
		for(auto &each : ranges[i]) {
			int right, value;
			tie(right, value) = each;
			dp[right] = max(dp[right], (i > 0 ? dp[i - 1] : 0) + value);
		}
	}

	printf("%d\n", dp[n - 1]);

	return 0;
}

