
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

using namespace std;

ll a[25];
int n;

int main() {
    cin >> n;
    rep(i,n){
    	cin >> a[i];
    }
    ll xormin = 1<<30;
    ll tmpx = 0;
    ll tmpo =0;
    if(n==1){
    	cout << a[0];
    	return 0;
    }
    rep(i,1<<(n-1)){
    	if(i == 0) continue;
        tmpx = 0;
        tmpo =0;
    	rep(j,n+1){
    		if(j == n){
    			tmpo = tmpo|a[j];
    			tmpx = tmpx^tmpo;
    			break;
    		}
    		tmpo = tmpo|a[j];
    		if(i&(1<<j)){
    			tmpx = tmpx^tmpo;
    			//,,cout << tmpo << endl;
    			tmpo = 0;
    		}
    	}
    	//cout << "-----" << tmpx << endl;
    	if(tmpx < xormin) xormin=tmpx;
    }
    cout << xormin;
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
#define M 1005
#define N 5005
#define Mod 1000000007
void read(LL &x){
	x=0;char c=getchar();LL f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
}
void print(LL x){
	if(x<10){
		putchar('0'+x);
		return ;
	}
	print(x/10);
	putchar(x%10+'0');
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	print(x);
	return ;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
char c[4];
LL n,f[M];
LL qkpow(LL a,LL k){
	LL ret=1;
	while(k){
		if(k&1)
			ret=ret*a%Mod;
		a=a*a%Mod;
		k>>=1;
	}
	return ret;
}
int main(){
	read(n);
	f[0]=1;
	f[1]=2;
	for(int i=2;i<=n;i++)
		f[i]=(f[i-1]+f[i-2])%Mod;
	for(int i=0;i<4;i++){
		c[i]=getchar();
		getchar();
	}
	if(n==2){
		write(1);
		return 0;
	}
	if(c[1]=='B'){
		if(c[3]=='B')
			write(1);
		else if(c[2]=='A')
			write(qkpow(2,n-3));
		else
			write(f[n-3]);
	}
	if(c[1]=='A'){
		if(c[0]=='A')
			write(1);
		else if(c[2]=='B')
			write(qkpow(2,n-3));
		else
			write(f[n-3]);
	}
} 