#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define lint long long
#define gc getchar()
#define N 200010
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int a[N],b[N];
int main()
{
	int n,anszero=1;scanf("%d",&n);lint ans=0ll;
	for(int i=1;i<=n;i++) a[i]=inn(),b[i]=inn();
	for(int i=1;i<=n;i++) if(a[i]^b[i]) anszero=false;
	if(anszero) return !printf("0\n");
	for(int i=1;i<=n;i++) if(a[i]<=b[i]) ans+=b[i];
	return !printf("%lld\n",ans);
}