#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[233333],b[233333];
int main()
{
	int n,f=0,bb=2147483647,aa;
	long long res=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		res=res+a[i];
		if(a[i]>b[i])
		{
			if(b[i]<bb)bb=b[i];
		}
		if(a[i]!=b[i])f=1;
	}
	printf("%lld",f?res-bb:0);
	return 0;
}