#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s2[100];
ll n;
ll qpow(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b/=2;
    }
    return res;
}
ll f(ll i)
{
    ll res;
    if(i==0)
        res=1;
    else if(s2[i-1]==1)
          res=f(i-1);
    else
          res=qpow(2,i)+f(i-1);
    return res;
}
int main()
{
    //int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++)
    {
      cin>>s;
      if(s=="AND")
         s2[i]=1;
      else
         s2[i]=0;
    }
    ll ans=f(n);
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

void testcase(){
	int n;
	cin>>n;

	vector<int> v1(n), v2(n);

	for(int i = 0; i<n; i++){
		cin>>v1[i]>>v2[i];
	}

	int l1 = INT_MAX, l2 = INT_MAX;
	int p1, p2;
	for(int i = 0; i<n; i++){
		if(v1[i] < l1){
			l1 = v1[i];
			p1 = i;
		}
		if(v2[i] < l2){
			l2 = v2[i];
			p2 = i;
		}
	}


	if(p1!=p2){
		cout<<max(l1, l2);
	}
	else{

	int L1 = INT_MAX, L2 = INT_MAX;

	
		for(int i = 0; i<n; i++){
			if(i != p1){
				if(v1[i]< L1){
					L1 = v1[i];
				}
			}
			if(i != p2){
				if(v2[i] < L2){
					L2 = v2[i];
				}
			}
		}

		cout<<min({l1+l2, max(l1, L2), max(l2, L1)});

	}





}

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

	testcase();
}