program ex;
var mx,mo,co,cx,zo,zx,w:longint;
begin
assign(input,'bs.in');
reset(input);
assign(output,'bs.out');
rewrite(output);
repeat
begin
readln(co,cx,mo,mx);
if (mo<>0)and(mx<>0) then
begin
zo:=co div mo;
zx:=cx div mx;
if co div mo<>0 then
inc(zo);
if cx div mx<>0 then
inc(zx);
if (co-zx>=-1)and(cx-zo>=-1) then
writeln(co+cx)
else
begin
if co-zx<-1 then
w:=co*mx+mx+co;
if cx-zo<-1 then
w:=cx*mo+mo+cx;
writeln(w);
end;
end
else
if mo=0 then
begin
if mx<=cx then
writeln(mx)
else
writeln(cx);
end
else
if mo<=co then
writeln(mo)
else
writeln(co);
end
until
eof(input);
close(input);
close(output);
end.