#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <stack>
#include <set>
#include <algorithm>
#include <bitset>
#include <functional>
#include <ctime>
#include <cassert>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <complex>
#include <regex>
#include <numeric>
#pragma comment(linker, "/STACK:167772160")

using namespace std;

template <typename T, typename Q>
ostream& operator<<(ostream& os, pair<T, Q> p)
{
	return (os << '(' << p.first << ", " << p.second << ')');
}

#define mp make_pair
#define rand govno_ebanoe
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " : " << (x) << endl
#define print_array(arr, len) {cerr << #arr << " : "; for(int i = 0; i < len; ++i) cerr << arr[i] << ' '; cerr << endl;}
#define print_2d_array(arr, len1, len2) {cerr << #arr << endl; for(int i = 0; i < len1; ++i, cerr << endl) for(int j = 0; j < len2; ++j) cerr << arr[i][j] << ' ';}
#define print_iterable(i) {cerr << #i << " : "; for(auto e : i) cerr << e << ' '; cerr << endl;}
#define print_new_line() cerr << endl
#else
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len) {}
#define print_2d_array(arr, len1, len2) {}
#define print_iterable(i) {}
#define print_new_line() (void)0
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const ld EPS = 1e-12;
#pragma endregion

#ifdef LOCAL
#define ERR_CATCH
//#define NOERR
#endif

const int N = 5e5 + 10;
int n;
char s[N];
int dp[N][3];

int solve_seg(int l, int r)
{
	vector<int> a;
	int sz = 0;
	for(int i = l; i <= r; ++i)
	{
		if (s[i] == 0)
		{
			a.push_back(sz);
			sz = 0;
		}
		else
			++sz;
	}
	a.push_back(sz);
	int n = a.size();
	for (int i = 0; i <= n; ++i)
		dp[i][0] = dp[i][1] = dp[i][2] = 0;
	dp[0][1] = 0;
	dp[0][2] = a[0];
	for (int i = 1; i < n; ++i)
	{
		dp[i][0] = max({ dp[i - 1][0], dp[i - 1][1] + a[i], dp[i - 1][2] });
		if (a[i] > 1)
			dp[i][1] = max({ dp[i - 1][0], dp[i - 1][2], dp[i - 1][1] + a[i] - 1 });
		else
			dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][2] = max({ dp[i - 1][0] + a[i], dp[i - 1][2] + a[i] - 1 });
	}
	return max(dp[n - 1][0], dp[n - 1][1]);
}

void solve()
{
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; ++i)
		s[i] -= '0';
	s[n++] = 0;
	s[n++] = 0;
	int ans = 0;
	int last_one = -1;
	for(int i = 0; i < n - 1; ++i)
	{
		if (s[i] == 1 && last_one == -1)
			last_one = i;
		else if(s[i] == 0 && s[i + 1] == 0 && last_one != -1)
		{
			ans += solve_seg(last_one, i - 1);
			last_one = -1;
		}
	}
	printf("%d\n", ans);
}

int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#ifdef NOERR
	freopen("err.txt", "w", stderr);
#endif
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif

#ifdef ERR_CATCH
	try
	{
#endif

#ifdef ST
		while (true)
			solve();
#endif

#ifdef CASES
#define MULTITEST
#endif

#ifdef MULTITEST
		int t;
		scanf("%d", &t);
		char endl1[5];
		fgets(endl1, 5, stdin);
		for (int i = 0; i < t; ++i)
		{
#ifdef CASES
			printf("Case #%d: ", i + 1);
#endif
			solve();
#ifdef CASES
			eprintf("Passed case #%d:\n", i + 1);
#endif
		}
#else
		solve();
#endif

#ifdef ERR_CATCH
	}
	catch (logic_error e)
	{
		print_var(e.what());
		puts("___________________________________________________________________________");
		exit(0);
	}
#endif
#ifdef LOCAL
	eprintf("\n\nTime: %.3lf\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 768