#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
long long n,a,b,change=2000000;
long long ans=0;
bool useA=false;
int main()
{
freopen("goz.in","r",stdin);
freopen("goz.out","w",stdout);
cin>>n;
long long i;
for(i=1;i<=n;i++)
{
cin>>a>>b;
change=min(change,b-a);
ans+=max(a,b);
if(a>=b)useA=true;
}
if(useA)cout<<ans<<endl;
else
{
ans-=change;
cout<<ans;
}
return 0;
}