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


#define BEFORES 0
#define FIRSTS 1
#define MIDS 2
#define SECONDS 3

long long N;
string S;
long long onedp[500005];
long long comdp[500005];
long long onlydp[500005];

long long cal(long long start, long long end){
	//cout << "cal" << endl;
	//cout << start << "," << end << endl;
	vector<long long> onevec;
	long long curnum = 0;
	bool conti = false;
	long long onecount = 0;
	for(long long i = start; i <= end; i++){
		if(S[i] == '1'){
			curnum++;
			onecount++;
		}else{
			//if(curnum > 0){
				onevec.push_back(curnum);
			//}
			curnum = 0;
		}
	}
	onevec.push_back(curnum);
	if(onevec.size() == 1){
		//cout << "none" << endl;
		return 0;
	}
	//cout << "valid" << endl;


	//cout << "onevec" << endl;
	for(long long i = 0; i < 2*onevec.size(); i++){
		onlydp[i] = -INT_MAX;
		onedp[i] = -INT_MAX;
		comdp[i] = -INT_MAX;
	}
	comdp[0] = 0;

	long long ans = 0;
	long long onesize = onevec.size();
	for(long long i = 0; i < onesize; i++){

		if(i + 1 < onesize){
			//ONEDP
			//1: skipp
			comdp[i+1] = max(comdp[i+1], onedp[i]);
			ans = max(ans, comdp[i+1]);

			//ONEDP
			//2: 現在の全消し, 次を1つ使う
			if(onevec[i+1]  > 1){
				onedp[i+1] = max(onedp[i+1], onedp[i] + onevec[i] - 1);
				ans = max(ans, onedp[i+1]);
			}else{
				comdp[i+2] = max(comdp[i+2], onedp[i] + onevec[i] - 1);
				ans = max(ans, comdp[i+2]);
			}

			//ONEDP
			//3: 次のを全消し
			comdp[i+2] = max(comdp[i+2], onedp[i] + onevec[i+1]);
			ans = max(ans, comdp[i+2]);

			//ONEDP
			//3: 次の1つ残して消す
			if(onevec[i+1]  > 1){
				onlydp[i+1] = max(onlydp[i+1], onedp[i] + onevec[i+1] - 1);
				ans = max(ans, onlydp[i+1]);
			}

			//COMDP
			//1: skipp
			comdp[i+1] = max(comdp[i+1], comdp[i]);
			ans = max(ans, comdp[i+1]);

			//COMDP
			//2: 現在の全部消し、次を1つ使う
			if(onevec[i+1]  > 1){
				onedp[i+1] = max(onedp[i+1], comdp[i] + onevec[i]);
				ans = max(ans, onedp[i+1]);
			}else{
				comdp[i+2] = max(comdp[i+2], comdp[i] + onevec[i]);
				ans = max(ans, comdp[i+2]);
			}

			//COMDP
			//3: 次を全消し
			comdp[i+2] = max(comdp[i+2], comdp[i] + onevec[i+1]);
			ans = max(ans, comdp[i+2]);

			//COMDP
			//4: 次を1つ残して消す
			if(onevec[i+1]  > 1){
				onlydp[i+1] = max(onlydp[i+1], comdp[i] + onevec[i+1] - 1);
				ans = max(ans, onlydp[i+1]);
			}
			
			//ONLYDP
			//1: skipp 
			comdp[i+1] = max(comdp[i+1], onlydp[i]);
			ans = max(ans, comdp[i+1]);

			//ONLYDP
			//2: 現在のを全部(1)消し、次の最初を消す
			if(onevec[i+1]  > 1){
				onedp[i+1] = max(onedp[i+1], onlydp[i] + 1);
				ans = max(ans, onedp[i+1]);
			}else{
				comdp[i+2] = max(comdp[i+2], onlydp[i] + 1);
				ans = max(ans, comdp[i+2]);
			}

			//ONLYDP
			//3: 次を全消し
			comdp[i+2] = max(comdp[i+2], onlydp[i] + onevec[i+1]);
			ans = max(ans, comdp[i+2]);


			//onlydp から次のを1つ残して消す
			if(onevec[i+1]  > 1){
				onlydp[i+1] = max(onlydp[i+1], onlydp[i] + onevec[i+1] - 1);
				ans = max(ans, onlydp[i+1]);
			}
		}

	}

	return ans;


}

int main(){
	cin >> N >> S;
	S+='0';
	S+='0';

	int state = BEFORES;
	long long spos = -1;
	long long ans = 0;

	for(long long i = 0; i <= N; i++){
		if(spos != -1 && S[i] == '0' && S[i+1] == '0'){
			ans += cal(spos, i - 1);
			spos = -1;
		}
		if(spos == -1 && S[i] == '1'){
			spos = i;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 4996