#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const long double eps = 1e-9;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0), b(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(b.begin(), b.end());
  cout << b[0] - 1 << endl;
  return 0;
}
