a, b = gets.not_nil!.split.map(&.to_i64) r = a % b if r < 0 r += b.abs end puts r