 //
#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    ll n;
    string t;
    cin >> n >> t;
    string s;
    char arr[] = {'1', '1', '0'};
    for(int i=0; i<=200005; i++)
    {
        s += arr[i%3];
    }
    const ll tot = 3*pow(10, 10);
    ll ans = 0;
    for(int i=0; i<3; i++)
    {
        if(s.substr(i, n) == t)
        {
            ans += 1 + (tot-i-n)/3;
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(void){
    int N;
    string S;
    vector<string> V;
    ll ans, cnt;
    bool flg;

    cin >> N;
    cin >> S;
    ans = 10000000000;
    cnt = 0;
    flg = false;

    
    for (int i = 0; i < N; i++){
        if (S[i] == '0'){
            if (i >= 1 && S[i - 1] != '1'){
                flg = true;
                break;
            }
            else if (i >= 2 && S[i - 2] != '1'){
                flg = true;
                break;
            }
            cnt++;
        }

        if (N >= 3){
            if (S.substr(i, 3) == "111"){
                flg = true;
                break;
            }
        }
    }

    

    if (!flg){
        if (N == 1 && S[0] == '1'){
            ans *= 2;
        }
        else if (N == 2 && S[0] == '1' && S[1] == '1'){
            ans *= 1;
        }
        else{
            if (S[N - 1] == '0') ans = ans - cnt + 1;
            else ans = ans - cnt;
        }
    }
    else ans = 0;
    
    cout << ans << endl;

    return 0;
}
