#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,a,b,s;
int main()
{
	scanf("%lld",&n);
	while(n--)
	{
		scanf("%lld %lld",&a,&b);
		s+=a;
		if(b<=a)
			s-=b;
	}
	printf("%lld\n",s);
}
