#include<cstdio>

const int INF = 1000000001;
int main() {
	int n;
	scanf("%d", &n);
	long long sum = 0;
	int m = INF;
	for(int i=0;i<n;i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		sum += a;
		if(a > b && b < m) m = b;
	}
	printf("%lld\n", m == INF ? 0 : sum - m);
	return 0;
}
