program bs;
var
i,j,k,l:longint;
x,xx,o,oo:longint;
s,ss,m,mm:longint;
function suan(x,y:longint):longint;
var
i:longint;
begin
i:=x mod y;
if i=0 then exit(x div y)
else exit((x div y)+1);
end;
procedure find;
var
i,j,k:longint;
begin
if ((ss<m)and(s>m))or((ss<mm)and(s>m))or((mm>ss)and(m<s))or((mm<s)and(m>s)) then
writeln(x+o)
else
begin
if ss>m then
begin
writeln(o+(m+1)*xx);
end
else
begin
writeln(x+(s+1)*oo);
end;
end;
end;
begin
assign(input,'bs.in');
reset(input);
assign(output,'bs.out');
rewrite(output);
while not eof do
begin
readln(x,o,xx,oo);
if x=0 then
begin
writeln(oo);
close(input);
close(output);
halt;
end;
if o=0 then
begin
writeln(xx);
close(input);
close(output);
halt;
end;
if xx=0 then
begin
writeln(oo);
close(input);
close(output);
halt;
end;
if oo=0 then
begin
writeln(xx);
close(input);
close(output);
halt;
end;
s:=x;
ss:=suan(x,xx);
m:=o;
mm:=suan(o,oo);
find;
end;
close(input);
close(output);
end.