#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

string to_string(const string &s) { return s; }

template <typename T, typename U>
string to_string(const P<T, U> &p) {
    string ret = "(";
    ret += to_string(p.first);
    ret += ", ";
    ret += to_string(p.second);
    ret += ")";
    return move(ret);
}

template <typename T>
string to_string(const V<T> &v) {
    string ret = "{";
    for(const T &t : v) {
        ret += to_string(t);
        ret += ", ";
    }
    ret += "}";
    return move(ret);
}

template <typename T>
void debug_func(const T &t, const string &s = "") {
    if(s.size()) cout << s << " = ";
    cout << to_string(t) << DEBUG_ENDL_S(s);
}

template <typename T>
void debug_func_mult(int idx, const V<string> &names, const T &t) {
    debug_func(t, names[idx]);
}

template <typename T>
void debug_func_mult(const V<string> &names, const T &t) {
    debug_func(t, names[0]);
}

template <typename Head, typename... Tail>
void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[idx]);
    debug_func_mult(idx + 1, names, args...);
}

template <typename Head, typename... Tail>
void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[0]);
    debug_func_mult(1, names, args...);
}

V<string> split_names(string &&s) {
    replace(ALL(s), ' ', ',');
    V<string> ret;
    istringstream ss(s);
    string t;
    while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t));
    return move(ret);
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

ll solve(string &s) {
    ll cnt = 0;
    V<ll> cntv;
    V<ll> oneidx;
    s += '0';
    for(char c : s) {
        if(c == '1') {
            cnt++;
        } else {
            cntv.push_back(cnt);
            cnt = 0;
        }
    }
    DEBUG(cntv);
    if(cntv.size() == 1) return 0;
    /*
     * 0 : get from right
     * 1 : get from left (do nothing to right)
     * 2 : give to right
     */
    VV<ll> dp(cntv.size() + 1, V<ll>(3, 0));
    for(ll i = 0; i < cntv.size(); i++) {
        dp[i + 1][0] = max(dp[i][0] + cntv[i] - 1, dp[i][1] + cntv[i]);
        dp[i + 1][1] = max(dp[i][0], (i == 0 ? 0 : dp[i][2] + cntv[i]));
        if(cntv[i] == 1) dp[i + 1][2] = max(dp[i][1], dp[i][2]);
        else dp[i + 1][2] = max(dp[i][0], (i == 0 ? 0 : dp[i][2] + cntv[i] - 1));
    }
    DEBUG(dp);
    ll idx = cntv.size();
    return max(dp[idx][1], dp[idx][2]);
}

int main() {
    init_io();
    ll N;
    cin >> N;
    string S;
    cin >> S;
    S += "00";
    V<string> vs;

    {
        ll preidx = 0;
        auto idx_inc = [&] { while(preidx < S.size() && S[preidx] != '1') preidx++; };
        char pre = '1';
        idx_inc();
        for(ll i = preidx; i < S.size(); i++) {
            if(S[i] == '0' && pre == '0') {
                ll len = i - 1 - preidx;
                DEBUG(len);
                if(len) vs.push_back(S.substr(preidx, len));
                preidx = i;
                idx_inc();
                i = preidx;
            }
            pre = S[i];
        }
    }

    DEBUG(vs);
    ll ans = 0;
    for(auto &s : vs) {
        ll v = solve(s);
        DEBUG(v);
        ans += v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5016