#include <iostream>
using namespace std;

int main(){
  long long n;
  cin >> n;
  long long count = 0;
  long long ma = 1e10;
  bool same = true;
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a != b) same = false;
    count += a;
    if (a > b) {
      ma = min(ma, b);
    }
  }
  if (same) cout << 0 << endl;
  else cout << count - ma << endl;
  return 0;
}
