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

int main()
{
    ll t,a,b;
    ll mab=1e9+10000;
    cin>>t;
    int flag=1;
    ll tot=0;
    while(t--)
    {
        cin>>a>>b;
        if(a>b&&mab>b)
            mab=b;
        tot+=b;
        if(a!=b) flag=0;
    }
    if(flag)
        cout<<0<<endl;
    else
        cout<<tot-mab<<endl;
    return 0;
}
