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() {
    immutable int INF = 1 << 29;

    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    Tuple!(int, int)[] A;

    foreach (i; 1..N-1) {
        if (S[i-1..i+2] != "101") continue;
        int a, b, p = i - 1;
        while (p >= 0 && S[p] == '1') p--;
        a = p + 1;
        p = i + 1;
        while (p < N && S[p] == '1') p++;
        b = p - 1;
        A ~= tuple(a, i+1);
        A ~= tuple(i-1, b);
    }

    A = A.uniq().array;
    int M = A.length.to!int;
    auto dp = new int[][](M, 2);
    foreach (i; 0..M) dp[i].fill(-INF);
    dp[0][0] = 0;
    dp[0][1] = A[0][1] - A[0][0] - 1;

    foreach (i; 1..M) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        if (A[i][0] > A[i-1][1]) {
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + A[i][1] - A[i][0] - 1;
        } else {
            dp[i][1] = dp[i-1][0] + A[i][1] - A[i][0] - 1;
        }
    }

    dp[M-1].reduce!max.writeln;
}
