#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define  m_p make_pair
#define x first
#define y second 
using namespace std;
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
using P=pair<int,int>;
const int inf=0x3f3f3f3f;
const LL LLinf=0x3f3f3f3f3f3f3f3f;

int main()
{
    IOS;
    #ifdef _DEBUG
    freopen("D:/CODE/algorithm_contest/out.txt","w",stdout);
    freopen("D:/CODE/algorithm_contest/in.txt","r",stdin);  
    #endif
    
    LL B,C;
    while(cin>>B>>C)
    {
        LL ans=0;
        if(B>0)
        {
            ans=C;
            if(C==1) ans++;
            ans+=min(C-2+1,2*B-1);
        }
        else if(B<0)
        {
            ans=C+1;
            ans+=max(min(-2*B-1,C-3+1),0ll);
        }
        else if(B==0)
        {
            ans=C;
        }
        cout<<ans<<endl;
    }
    return 0;
}

// Code for B - Many 110
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

int main() {
  int N;
  cin >> N;
  string T;
  cin >> T;

  if (T == "0") {
    cout << 10000000000 << endl;
    return 0;
  }

  if (T == "1") {
    cout << 20000000000 << endl;
    return 0;
  }

  if (T == "11") {
    cout << 10000000000 << endl;
    return 0;
  }

  // if (T == "110") {
  //   cout << 10000000000 << endl;
  //   return 0;
  // }

  // if (T == "011") {
  //   cout << 9999999999 << endl;
  //   return 0;
  // }

  // if (T == "101") {
  //   cout << 9999999999 << endl;
  //   return 0;
  // }

  string base = "110";
  bool any = false;
  ll start;
  REP(j, 3) {
    bool isOk = true;
    REP(i, N) {
      if (T[i] != base[(i + j) % 3]) {
        isOk = false;
        break;
      }
    }
    if (isOk) {
      any = true;
      start = j;
      break;
    }
  }

  if (!any) {
    cout << 0 << endl;
    return 0;
  }

  if (start == 1) {
    start = 2;
  } else if (start == 2) {
    start = 1;
  }

  ll m = ( N - start ) / 3;
  ll end = ( N - start ) % 3;

  // cout << 10000000000 - (( start + end ) / 3) - (m - 1);
  cout << 10000000000 - (start > 0 ? 1 : 0) - (m - 1) - (end > 0 ? 1 : 0);
  return 0;
}
