#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template <class T>
bool chmax(T& a, const T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int n;
    cin >> n;
    VLL A(n), B(n);
    REP(i, n) {
        cin >> A[i] >> B[i];
    }
    ll ans = INF;
    REP(i, n) {
        REP(t, n) {
            if (i == t) {
                chmin(ans, A[i] + B[t]);
            } else {
                chmin(ans, max(A[i], B[t]));
            }
        }
    }
    COUT(ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000

string complement(string s)
{
	string t="";
	for(int i=0;i<s.length();i++)
	{
		if(s.at(i)=='A')
			t+='B';
		else
			t+='A';
	}
	return t;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int power2[9];
	power2[0]=1;
	for(int i=1;i<9;i++)
		power2[i]=power2[i-1]*2;
	vector<string> ans[9];
	for(int i=1;i<9;i++)
	{
		for(int j=0;j<ans[i-1].size();j++)
		{
			string z=ans[i-1][j];
			string w=complement(z);
			string x=z+z;
			string y=z+w;
			ans[i].push_back(x);
			ans[i].push_back(y);
		}
		string a="";
		for(int j=0;j<power2[i-1];j++)
		{
			a+='A';
		}
		for(int j=0;j<power2[i-1];j++)
		{
			a+='B';
		}
		ans[i].push_back(a);
	}
	int tt=1;
	//cin >> tt;
	while(tt--)
	{
		int n;
		cin >> n;
		cout << ans[n].size() << '\n';
		for(int i=0;i<ans[n].size();i++)
			cout << ans[n][i] << '\n';
	}
	return 0;
}