#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main(){
    long i,n,t=0,a,b,min=1000000000;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        t=t+a+b;
        if((b<min)and(a>b)){
            min=b;
        }
    }
    t=t-2*min;
    if(min==1000000000){
        cout<<0;
        return 0;
    }
    cout<<t/2;
}