#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, pair<long long int, long long int> > > v;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a - b, make_pair(a, b)));
  }
  sort(v.begin(), v.end());
  long long int p = 0;
  for (long long int i = 0; i < n; i++) {
    p += v[i].first;
    if (i == 0 && p >= 0) {
      cout << "0 1" << endl;
      return 0;
    }
    cout << "hage" << endl;
    return 0;
    long long int b = v[i].second.second;
    cout << "  : " << v[i].second.first << " : " << b << endl;
    if (p > b) {
      p -= b;
      continue;
    }
    cout << ((n - 1 - i) * b + p) << " " << n * b << endl;
    return 0;
  }
  return 0;
}
