#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int ans=0;
    int m=-1;
    sort(a,a+n);
    int mx=a[n-1];
    for(int i=2; i<=mx; i++){
            int c=0;
        for(int j=0; j<n; j++){
            if(a[j]%i==0){
                c++;
            }
        }
        if(c>=m){
            m=c;
            ans=i;
        }

    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;
	string s;
	cin>>s;

	if(s=="1"){
		cout<<2LL*ll(1e10)<<endl;
		return 0;
	}

	for(int i=0; i<3; i++){
		bool w=1;
		for(int j=0; j<n; j++){
			if(j%3 == i){
				if(s[j] != '0'){
					// if(!w) cout<<i<<" "<<j<<endl;
					w=0;
				}
			}

			else{
				if(s[j] != '1'){
					// if(!w) cout<<i<<" "<<j<<endl;
					w=0;
				}
			}	

			if(j==n-1 && w){

				ll ans = ll(3e10)-n;

				if(i==0){
					// we end at n+2, n+5, ...
					ans++;
				}

				if(i==1){
					// we end at n+1, n+4, ...
					ans+=2;
				}

				if(i==2){
					ans+=3;
				}

				cout<<ll(ans/3LL)<<endl;
				return 0;
			}
		}
	}

	cout<<0<<endl;
}