var
a,b,a1,b1,c,o,x,o1,x1,ans:longint;
begin
assign(input,'bs.in');
assign(output,'bs.out');
reset(input);
rewrite(output);
while not eof do
begin
read(o,x,o1,x1);
if (eof)and(o=0)and(x=0)and(o1=0)and(x1=0) then break;
ans:=0;c:=0;
if o1>o then o1:=o;
if x1>x then x1:=x;
if (o1=0)and(c=0) then
begin
writeln(x1);
c:=1;
end;
if (x1=0)and(c=0) then
begin
writeln(o1);
c:=1;
end;
if c=0 then
begin
if o mod o1=0 then a:=o div o1
else a:=o div o1+1;
if x mod x1=0 then b:=x div x1
else b:=x div x1+1;
if (c=0)and((a<=x+1)and(a>=b-1))or((b<=o+1)and(b>=a-1))then ans:=o+x
else begin
if a>x+1 then
if (c=0)and((x+1)*o1>o) then ans:=x+o
else ans:=x+(x+1)*o1;
if b>o+1 then
if (c=0)and((o+1)*x1>x) then ans:=x+o
else ans:=o+(o+1)*x1;
end;
writeln(ans);
end;
end;
close(input);close(output);
end.