import strscans
let(_,a,b,n,m)=stdin.readAll.scanTuple"$i $i $i $i"
echo case a.cmp b
of 0:a
of 1:(a-b)/%(n+1)+b
else:(b-a)/%(m+1)+a