#include <bits/stdc++.h>
#pragma GCC diagnostic warning "-std=c++11"
 
#define ll long long 
#define pb  push_back
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define sl(n)  scanf("%lld", &n)
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
 
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin>>n;
	string t;
	cin>>t;

	ll x = 1e10;
	if(t=="11" or t=="0" or t=="110"){
		cout << x << "\n";
		return 0;
	}
	if(t=="1"){
		cout << 2*x << endl;
		return 0;
	}

	string s = "110";
	
	bool flag = false;
	ll fst;
	for(ll i=0;i<3;i++){
		ll st = i, j;
		for(j=0;j<n;j++){ //loop whole t. 
			ll ind = (i+j)%3;
			char ch = s[ind];
			if(t[j] != ch){
				break;
			}
		}
		if(j==n){
			flag = true;
			fst = i;
			break;
		}
	}
	if(flag==false){
		cout << 0 << "\n";
		return 0;
	}
	// cout << fst << endl;
	ll tot = 3*1e10;
	// cout << tot << endl;
	// cout << (tot-fst)/n << endl;

	tot-=n;
	ll ans = (tot-fst)/3;
	ans++;
	cout << ans << "\n";
	return 0;
}
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  string t;
  cin >> t;
  string s = "";
  while ((int) s.size() <= n) {
    s += "110";
  }
  s += s;
  const int long long SN = 3e10;
  long long ans = 0;
  
  // first
  {
    if (s.substr(0, n) == t) {
      long long st = SN - n;
      ans += st / 3 + 1;
    }
  }
  // second
  {
    if (s.substr(1, n) == t) {
      long long st = SN - n;
      st--;
      ans += st / 3 + 1;
    }
  }
  // third
  {
    if (s.substr(2, n) == t) {
      long long st = SN - n;
      st -= 2;
      ans += st / 3 + 1;
    }
  }
  cout << ans << endl;
  return 0;
}