	#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const db PI = acos(-1);
const db ERR = 1e-12;

const int MX = 500005;

char buf[MX];
int D[MX];

int main()
{
	int N;
	scanf("%d%s", &N, buf+1);
	int ans = 0, cur = 0;
	vector<int> L;
	for(int i = 1; i <= N; i++){
		if( buf[i] == '1' ) cur++;
		else cur = 0;
		D[i] = max(D[i], D[i-1]);
		if( cur && buf[i+1] == '0' && buf[i+2] == '1' )
{ D[i+2] = max(D[i+2], D[i-cur] + cur);D[i+2] = max(D[i+2], D[i-cur+1] + cur-1);}
		if( cur && i >= cur+2 && buf[i-cur] == '0' && buf[i-cur-1] == '1' ) D[i] = max(D[i-cur-2] + cur, D[i]);
	}
	printf("%d\n", D[N]);
	return 0;
}