program ex_1;
var a,b,c,n,i,total,temp:longint;
j:boolean;
begin
assign(input,'goz.in'); reset(input);
assign(output,'goz.out'); rewrite(output);
readln(n);
j:=false; temp:=maxlongint;
for i:=1 to n do
begin
readln(a,b);
if a>=b then begin
total:=total+a;
j:=true;
end
else begin
total:=total+b;
c:=b-a;
if c<temp then temp:=c;
end;
end;
if j then writeln(total)
else writeln(total-c);
close(input); close(output);
end.