#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int N,i;
	cin >> N;
	long long A[N],B[N],minB=999999999,M=0,f=0;
	for (i=0;i<N;++i) {
		cin >> A[i] >> B[i];
		if (A[i]>B[i]) {
			if (B[i]<minB) {
				minB=B[i];
			}
		}
		M+=A[i];
		if (A[i]!=B[i]) f=1;
	}
	if (f==0) {
		cout << 0 << endl;
		return 0;
	}
	cout << M-minB << endl;
	return 0;
}
