a,b = gets.split.map(&:to_i) if a>b then puts 1999999999 - b elsif puts b-2 end