($A,$B,$_,$b)=glob<>;$_+=$A while$_%$B-$b;print