N, D = gets.split.map(&:to_i) ans = D.lcm(N) / D - 1 puts ans