#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    cin>>b[i];
  }
  int result=100000000;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      result=min(result, i==j ?(a[i]+b[j]):max(a[i],b[j]));
    }
  }
  cout<<result;
   return 0;
 }
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){

  int n;cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;++i)cin>>s[i];

  vector<vector<int>>dp(n, vector<int>(2,0));

  //base case ==> dp[0][0] && dp[0][1]
  if(s[0]=="AND"){
    dp[0][0]= 3;
    dp[0][1]= 1;
  }else{
    dp[0][0]= 1;
    dp[0][1]= 3;
  }

  for(int i=1;i<n;++i){
    if(s[i]=="AND"){
      dp[i][0] = 2*dp[i-1][0] + dp[i-1][1];
      dp[i][1] = 0 + dp[i-1][1];
    }else{
      dp[i][0] = dp[i-1][0] + 0;
      dp[i][1] = 2*dp[i-1][1] + dp[i-1][0]; 
    }
  }
  cout<<dp[n-1][1]<<endl;


  return 0;}
