#include<cstdio>
#include<algorithm>
using std::min;

const int N=200000;

int main()
{
	int a,b,n,Min=0x5FFFFFFF;
	long long S=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a,&b);
		S+=a;
		if(a>b)
			Min=min(Min,b);
	}
	if(Min==0x5FFFFFFF)
		puts("0");
	else
		printf("%lld\n",S-Min);
	return 0;
}