program aa;
var
maxa,maxb,suma,sumb:longint;
function min(a,b:longint):longint;
begin
if a>b then exit(b)else exit(a);
end;
function fct:longint;
begin
maxa:=min(maxa,suma);
maxb:=min(maxb,sumb);
if maxa=0 then exit(maxb);
if maxb=0 then exit(maxa);
if (suma+sumb)div(sumb+1)>maxa then exit((sumb+1)*maxa+sumb);
if (suma+sumb)div(suma+1)>maxb then exit((suma+1)*maxb+suma);
exit(suma+sumb);
end;
begin
while not eof do
begin
readln(suma,sumb,maxa,maxb);
writeln(fct);
end;
end.