#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
vector<string> split(string s, string word) {
    s += word;
    vector<string> vs;
    string added_word;
    for (int i = 0; i + word.size() - 1 < s.size(); i++) {
        string tmp = s.substr(i, word.size());
        if (tmp == word) {
            vs.push_back(added_word);
            added_word = "";
        } else {
            added_word += s[i];
        }
    }

    return vs;
}

int calc(string s) {
    s.erase(s.end() - 2, s.end());
//    cout << s << endl;
    auto vs = split(s, "0");
    vector<int> v;
    for (auto e : vs) {
        v.push_back(e.size());
    }

    if (v.size() == 1) return 0;

    int n = v.size();
    vector<vector<int> > dp(v.size(), vector<int>(5, 0));

    for (int i = 1; i < n; i++) {
        rep(k, 0, 5) {
            dp[i][1] = dp[i][0] = max(dp[i][0], dp[i - 1][k]);
        }
        if (v[i] == 1) {
            if (v[i - 1] == 1) {


                dp[i][4] = max({dp[i - 1][0] + max(v[i - 1], v[i]),
                                dp[i - 1][1] + max(v[i - 1], v[i]),
                                dp[i - 1][4]
                               });

                dp[i][2] = dp[i][1];
                dp[i][3] = dp[i][4];
            } else {


                dp[i][4] = max({dp[i - 1][0] + max(v[i - 1], v[i]),
                                dp[i - 1][1] + max(v[i - 1], v[i]),
                                dp[i - 1][2] + max(v[i - 1] - 1, v[i]),
                                dp[i - 1][3] + v[i],
                                dp[i - 1][4]
                               });

                dp[i][2] = dp[i][1];
                dp[i][3] = dp[i][4];
            }
        } else {
            if (v[i - 1] == 1) {
                dp[i][2] = max({dp[i - 1][0] + v[i - 1],
                                dp[i - 1][1] + v[i - 1],
                                dp[i - 1][4]
                               });

                dp[i][3] = max({dp[i - 1][0] + max(v[i - 1], v[i] - 1),
                                dp[i - 1][1] + max(v[i - 1], v[i] - 1),
                                dp[i - 1][4]
                               });

                dp[i][4] = max({dp[i - 1][0] + max(v[i - 1], v[i]),
                                dp[i - 1][1] + max(v[i - 1], v[i]),
                                dp[i - 1][4]
                               });
            } else {
                dp[i][2] = max({dp[i - 1][0] + v[i - 1],
                                dp[i - 1][1] + v[i - 1],
                                dp[i - 1][2] + v[i - 1] - 1,
                                dp[i - 1][3] + 1,
                                dp[i - 1][4]
                               });
                dp[i][3] = max({dp[i - 1][0] + max(v[i - 1], v[i] - 1),
                                dp[i - 1][1] + max(v[i - 1], v[i] - 1),
                                dp[i - 1][2] + max(v[i - 1] - 1, v[i] - 1),
                                dp[i - 1][3] + v[i] - 1,
                                dp[i - 1][4]
                               });

                dp[i][4] = max({dp[i - 1][0] + max(v[i - 1], v[i]),
                                dp[i - 1][1] + max(v[i - 1], v[i]),
                                dp[i - 1][2] + max(v[i - 1] - 1, v[i]),
                                dp[i - 1][3] + v[i],
                                dp[i - 1][4]
                               });
            }
        }


//        dp[i][2] = max({dp[i - 1][0] + v[i - 1],
//                        dp[i - 1][1] + v[i - 1],
//                        dp[i - 1][2] + v[i - 1] - 1,
//                        dp[i - 1][3] + 1,
//                        dp[i - 1][4]
//                       });
//
//        dp[i][3] = max({dp[i - 1][0] + max(v[i - 1], v[i] - 1),
//                        dp[i - 1][1] + max(v[i - 1], v[i] - 1),
//                        dp[i - 1][2] + max(v[i - 1] - 1, v[i] - 1),
//                        dp[i - 1][3] + v[i] - 1,
//                        dp[i - 1][4]
//                       });
//
//        dp[i][4] = max({dp[i - 1][0] + max(v[i - 1], v[i]),
//                        dp[i - 1][1] + max(v[i - 1], v[i]),
//                        dp[i - 1][2] + max(v[i - 1] - 1, v[i]),
//                        dp[i - 1][3] + v[i],
//                        dp[i - 1][4]
//                       });
    }

    int ret = -1;
    rep(i, 0, 5) {
        ret = max(ret, dp[n - 1][i]);
    }

    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    string s;
    cin >> s;
    s += "00";
    vector<string> ss;
    int state = 0;
    string tmp;
    int ans = 0;
    rep(i, 0, s.size()) {
        if (state == 0) {
            if (s[i] == '1') {
                state = 1;
                i--;
            }
        } else if (state == 1) {
            tmp += s[i];
            if (tmp.size() > 2 && tmp.back() == '0' && *(tmp.end() - 2) == '0') {
                ans += calc(tmp);
                tmp = "";
                state = 0;
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3320