#include <fstream>
using namespace std;
ifstream fin("goz.in");
ofstream fout("goz.out");
long long i, n, a, b, result = 0, maxvalue = -20000000;
bool flag = false;
int main()
{
fin >> n;
for(i = 0; i < n; i++)
{
fin >> a;
fin >> b;
if(a >= b)
{
flag = true;
result += a;
}
else
{
result += b;
if((a-b) > maxvalue)
{
maxvalue = a-b;
}
}
}
if(flag == false)
{
result += maxvalue;
}
fout << result;
fin.close();
fout.close();
return 0;
}