var
max,ff,count:array[0..1] of longint;
i,ans:longint;
procedure swap(var a,b:longint);
begin
a:=a xor b;
b:=a xor b;
a:=a xor b;
end;
begin
assign(input,'bs.in');
assign(output,'bs.out');
reset(input);
rewrite(output);
//while not(eof) do
//begin
while not(eof) do
begin
readln(count[0],count[1],max[0],max[1]);
if max[0]=0 then
begin
if count[1]>=max[1] then
writeln(max[1])
else
writeln(count[1]);
continue;
end;
if max[1]=0 then
begin
if count[0]>=max[0] then
writeln(max[0])
else
writeln(count[0]);
continue;
end;
for i:=0 to 1 do
if count[i] mod max[i]=0 then
ff[i]:=count[i] div max[i]
else
ff[i]:=count[i] div max[i]+1;
ans:=count[0]+count[1];
if count[0]+1<ff[1] then
dec(ans,count[1]-(count[0]+1)*max[1]);
if count[1]+1<ff[0] then
dec(ans,count[0]-(count[1]+1)*max[0]);
writeln(ans);
end;
//end;
close(input);
close(output);
end.