#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int r,o;
int sum=0,mins=0x3f3f3f3f;
for(int i=0;i<n;i++)
{
cin>>r>>o;
mins=min(mins,r-o);
sum+=o;
//mins=max(mins,sum);
}
sum+=mins;
cout<<sum<<endl;
return 0;
}