// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=998244353;
const int inf = 1e14;
const int LOG=17;
const int N=5e3+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
void solve(){
cin >> n;
double ans=0;
double c1=0,c2=0;
vector<double>a(n),b(n);
for (int i=0;i<n;i++){
cin >> a[i] >> b[i];
}
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
int i=0;
int j=0;
while (i<n and j<n){
if (c1<=c2){
c1+=a[i];
c++;
i++;
ans=max(ans,min(c1,c2)-c);
}
else{
c2+=b[j];
c++;
j++;
ans=max(ans,min(c1,c2)-c);
}
}
while (i<n){
c1+=a[i];
c++;
i++;
ans=max(ans,min(c1,c2)-c);
}
while (j<n){
c2+=b[j];
c++;
j++;
ans=max(ans,min(c1,c2)-c);
}
cout << ans << endl;
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r" ,stdin);
// freopen("output.txt","w",stdout);
// #endif
ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
cout << fixed << setprecision(9);
srand(time(0));
// int t=1;
// cin >> t;
for (int _=1;_<=t;_++){
solve();
q++;
}
}