#include<cstdio>
#include<algorithm>
using namespace std;
long long minb=10000000000,a,b,n;
bool flag;
long long ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&a,&b);
		ans+=b;
		if(a>b) {
			minb=min(b,minb);
			flag=1;
		}
		if(a!=b)
			flag=1;
	}
	if(flag)
		printf("%lld",ans-minb);
	else
		puts("0");
}