// 2021-03-06 21:04:00
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

// clang-format on
const int inf = 1e9;
void answer() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  int ans = inf;
  rep(i, n) rep(j, n) {
    if (i == j) {
      chmin(ans, a[i] + b[i]);
    } else {
      chmin(ans, max(a[i], b[j]));
    }
  }
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

int n, k;

int main()
{
	cin >> n >> k;

	for (int i = 0; i < k; i++) {
		vector<int> g;

		while (n > 0) {
			g.push_back(n % 10);
			n /= 10;
		}

		sort(g.begin(), g.end());
		int u = 0;

		for (int j : g) {
			u *= 10;
			u += j;
		}

		reverse(g.begin(), g.end());

		int v = 0;

		for (int j : g) {
			v *= 10;
			v += j;
		}

		n = v - u;
	}

	cout << n << endl;
}
