program Project1;
procedure init;
begin
assign(input,'bs.in');reset(input);
assign(output,'bs.out');rewrite(output);
end;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
procedure main;
var co,cx,mo,mx,dix,dio:int64;
begin
while not eof do
begin
readln(co,cx,mo,mx);
if (mo=0)and(mx=0) then begin writeln(0);continue;end;
if (mo=0) then begin writeln(min(mx,cx));continue;end;
if (mx=0) then begin writeln(min(mo,co));continue;end;
if (mo=1)and(mx=1) then begin writeln(min(co,cx)*2+1);continue;end;
dio:=co div mo;if dio*mo<co then inc(dio);
dix:=cx div mx;if dix*mx<cx then inc(dix);
if abs(dix-dio)<=1 then writeln(co+cx) else
if dix<dio then
writeln((cx+1)*mo+cx)
else
writeln((co+1)*mx+co);
end;
close(input);
close(output);
end;
begin
init;
main;
end.