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

#define int long long
#define REP(i,n) for(int i=0;i<n;i++)

int n,a,b;

signed main(void){
    int f=0;
    int s=0;
    int u=1e9;
    cin>>n;
    REP(i,n){
        cin>>a>>b;
        s+=a;
        if(a>b){u=min(b,u);f=1;}
    }
    cout<<f*(s-u)<<endl;
}
