#include <iostream>
#include <vector>

using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long int> A(N), B(N);
  int M = 0;
  long long int ans = 0, d = 0, m = 1e15;
  for(int i = 0; i < N; ++i){
    cin >> A[i] >> B[i];
    ans += A[i];
    if(A[i] > B[i]){
      m = min(m, B[i]);
    }
  }
  ans -= m;
  cout << max(0LL, ans) << endl;
  return 0;
}
