#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 5e5+5;
string s;

int n, l[MAXN];
int dp[MAXN];

int main() {
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		if (i == 0) {
			l[i] = (s[i] == '1');
		} else {
			if (s[i] == '0')
				l[i] = 0;
			else
				l[i] = l[i-1]+1;
		}
	}

	dp[0] = dp[1] = dp[2] = 0;

	for (int i = 2; i < n; ++i) {
		//case 1: you have 101111....1
		dp[i+1] = dp[i];
		int k = l[i];
		if (k <= i-1 && s[i-k] == '0' && s[i-k-1] == '1')
			dp[i+1] = max(dp[i+1], dp[i-k-1]+k);
		if (s[i] == '1' && s[i-1] == '0' && s[i-2] == '1') {
			k = l[i-2];
			dp[i+1] = max(dp[i+1], dp[i-k-1]+k);
			if (k >= 2)
				dp[i+1] = max(dp[i+1], dp[i-k]+k-1);
		}
	}

	cout << dp[n] << endl;
}