#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
vector<vector<ll>> split(const string& s0) {
    const string s = s0 + "00";
    const ll n = s.size();
    vector<vector<ll>> res;
    // 0: 00...(1待ち), 1: 11...(0待ち), 2: 0 (次に1来て)
    ll mode = 0;
    vector<ll> v;
    each(c, s) {
        switch (mode) {
        case 0:
            if (c == '1') {
                mode = 1;
                v.assign(1, 1);
            }
            break;
        case 1:
            if (c == '1') {
                v.back()++;
            }
            else {
                mode = 2;
            }
            break;
        case 2:
            if (c == '1') {
                v.pb(1);
                mode = 1;
            }
            else {
                res.pb(v);
                v.clear();
                mode = 0;
            }
            break;
        }
    }
    return res;
}
ll solve(const vector<ll>& v) {
    const ll n = v.size();
    // 0: 左に使った(-1), 1: 左のを使った(=0), 2: 何もしていない(+0), 3: 左のを使って1つ残す(=1)
    vector<vector<ll>> dp(n+1, vector<ll>(4, -linf));
    dp[1][2] = 0;
    rep(i, 1, n) rep(j, 4) {
        if (dp[i][j] < 0) continue;
        ll left = j == 0 ? v[i-1]-1 : j == 1 ? 0 : j == 2 ? v[i-1] : 1;
        ll right = v[i];
        // 左に使う
        if (left > 0 && right > 0) {
            chmax(dp[i+1][0], dp[i][j]+left);
        }
        // 左のを使う
        if (left > 0 && right > 0) {
            chmax(dp[i+1][1], dp[i][j]+right);
        }
        // 何もしない
        chmax(dp[i+1][2], dp[i][j]);
        // 左のを使って1つ残す
        if (left > 0 && right > 0) {
            chmax(dp[i+1][3], dp[i][j]+right-1);
        }
    }
    ll res = 0;
    rep(i, 3) chmax(res, dp[n][i]);
    // cout << v << endl;
    // cout << dp << endl << endl;
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    string s; cin >> s; n = s.size();
    vector<vector<ll>> v = split(s);
    ll ans = 0;
    each(seq, v) {
        ans += solve(seq);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7060