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

int n, x, y;
long long sum;

int main(void) {
  scanf("%d", &n);
  int mi = 0x3f3f3f3f, flg = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if(x != y) flg = 1;
    sum += x;
    if(x > y) mi = min(mi, y);
  }
  printf("%lld\n", !flg ? 0 : sum - mi);
  return 0;
}
