#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, s, h = 0, t = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k >> s;
    if (k > s) {
      h = h + k;
    } else if (s > k) {
      t = t + s;
    }
  }
  if (h < t) {
    cout << t << endl;
  } else if (t < h) {
    cout << h << endl;
  } else if (t == h) {
    cout << h << endl;
  }
  return 0;
}
