#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  int N, A[100000], B[100000];

  cin >> N;

  int64 all = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    all += A[i];
  }

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    if(A[i] > B[i]) {
      ret = max(ret, all - B[i]);
    }
  }

  cout << ret << endl;
}
