#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"

const int MAXN = 5e5 + 10;

int n;
char s[MAXN];

bool read() {
	if  (scanf("%d\n", &n) < 1) {
		return 0;
	}
	scanf("%s\n", s);
	return 1;
}

const int INF = 1e9;

void remax(int& x, int y) {
	if  (x < y) {
		x = y;
	}
}

int get(const vii& segs) {
	if  (sz(segs) <= 1) {
		return 0;
	}

	vi x;
	for (const auto& s : segs) {
		x.pb(s.snd - s.fst + 1);
	}

	vvi dp(sz(x) + 1, vi(3, 0));
	dp[0][0] = 0;
	dp[0][1] = -INF;
	dp[0][2] = -INF;

	// forn(i, sz(x)) {
	// 	eprintf("%d ", x[i]);
	// }
	// eprintf("\n");

	for (int pref = 1; pref <= sz(x); ++pref) {
		const int i = pref - 1;

		forn(was, 2) {
			remax(dp[pref][was], dp[pref - 1][0]);

			if  (was == 1 && x[i] == 1) {
				continue;
			}

			remax(dp[pref][was], dp[pref - 1][1] + (x[i] - (was == 1)));

			if  (pref > 1) {
				remax(dp[pref][was], dp[pref - 2][0] + x[i - 1]);

				if  (x[i - 1] > 1) {
					remax(dp[pref][was], dp[pref - 1][2] + (x[i - 1] - 1));
				}
			}

			// eprintf("pref = %d, was = %d --> %d\n", pref, was, dp[pref][was]);
		}

		remax(dp[pref][2], dp[pref - 1][0]);
		remax(dp[pref][2], dp[pref - 1][1] + 1);
		if  (pref > 1) {
			remax(dp[pref][2], dp[pref - 2][0] + x[i - 1]);

			if (x[i - 1] > 1) {
				remax(dp[pref][2], dp[pref - 1][2] + (x[i - 1] - 1));
			}
		}
	}

	return dp[sz(x)][0];
}

int solve() {
	vii segs;
	for (int i = 0, j = 0; i < n; i = j) {
		if  (s[i] == '0') {
			j = i + 1;
			continue;
		}
		while (j < n && s[i] == s[j]) {
			++j;
		}

		segs.pb(mp(i, j - 1));
	}

	int ans = 0;

	vii cur;
	for (const auto& s : segs) {
		int l, r;
		tie(l, r) = s;
		if  (cur.empty() || cur.back().snd + 2 == l) {
			cur.pb(s);
		} else {
			ans += get(cur);
			cur = {s};
		}
	}

	ans += get(cur);

	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%d\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 1912