#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,x,y;
	long long sum=0,mn=1000000007;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		sum+=x;
		if(x>y)
			mn=min(mn,(long long)y);
	}
	if(mn==1000000007)
		mn=sum;
		
	printf("%lld",sum-mn);
	return 0;
}
