#include<bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e9+1;

signed main() {
	int N;
	cin >> N;
	
	vector<int> A(N), B(N);
	int ans = 0;
	int mi = INF;
	for ( int i = 0; i < N; i++ ) {
		cin >> A[i] >> B[i];
		if ( A[i] > B[i] ) mi = min(mi, B[i]);
		ans += A[i];		
	}

	ans -= mi;
	if ( A == B ) ans = 0;
	cout << ans << endl;
	
	return 0;
}
