import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;


void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto T =
        S.
        replace(ctRegex!(`^0+`), "").
        replace(ctRegex!(`0+$`), "").
        split(ctRegex!(`00+`)).
        map!(s => s.split('0').map!(t => t.length.to!int).array).
        filter!(a => a.length > 1).
        array;

    T.map!(t => t.solve).sum.writeln;
}

long solve(int[] A) {
    immutable int INF = 1 << 29;

    int N = A.length.to!int;
    auto dp = new int[][](N, 3);
    foreach (i; 0..N) dp[i].fill(-INF);
    dp[0][0] = 0;

    foreach (i; 0..N-1) {
        dp[i+1][0] = max(dp[i][0],
                         dp[i][1],
                         dp[i][2]);
        dp[i+1][1] = max(dp[i][0] + A[i],
                         dp[i][1] + A[i] - 1);
        dp[i+1][2] = max(dp[i][0] + A[i+1],
                         (dp[i][1] + A[i+1]) * (A[i] > 1));
    }

    return dp[N-1].reduce!max;
}
