#!/usr/bin/ruby
a,b=gets.split.map(&:to_i)
if a<b
	p b-2
else
	p 2000000000-b-1
end