#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	long long ans = 0;
	int mn = 1000000000;
	bool equall = true;
	for (int i = 1; i <= n; ++ i){
		int x, y;
		cin >> x >> y;
		if (x != y)
			equall = false;
		ans += x;
		if (x > y)
			mn = min(mn, y);
	}
	if (equall)
		cout << 0 << endl;
	else
		cout << ans - mn << endl;
}
