N, D = gets.split.map(&:to_i) if N.gcd(D) == 1 puts N - 1 else puts N / D - 1 end