#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int a,b;
    cin >> a >> b;
    int mx=0;
    for (int k=1; k<=b; k++)
    {
      int z = (a+k-1)/k;
      int first = z*k;
      int second = (z+1)*k;
      if (first>=a && second<=b) mx = k;
    }
    cout << mx;
}

int main()
{
int t=1;
//cin >> t;
while (t--) solve();
}

#if _local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
using i64 = int64_t;
using pll = std::pair<int64_t,int64_t>;
constexpr char newl = '\n';
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U>std::istream&operator>>(std::istream&is,std::pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T,class U>std::ostream&operator<<(std::ostream&os,std::pair<T,U>const&p){os<<p.first<<" "<<p.second;return os;}
#if _local
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){std::cerr<<elm<<std::flush;return*this;}}dout;
#else
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){return*this;}}dout;
#endif

int main() {
  int n;
  cin >> n;
  vector<pll> a(n);
  cin >> a;
  i64 bsum = 0;
  for (auto [b, _] : a)
    bsum += b;
  auto cmp = [](pll a, pll b) {
    return a.first * 2 + a.second > b.first * 2 + b.second;
  };
  sort(begin(a), end(a), cmp);
  i64 asum = 0;
  int ans = 0;
  rep(i, n) {
    asum += a[i].first + a[i].second;
    bsum -= a[i].first;
    ans = i + 1;
    if (asum > bsum)
      break;
  }
  dout << asum << " " << bsum << newl;
  cout << (ans) << endl;
}
