a,b = map(int, raw_input().split()) if a > b: print 1999999999 - b else: print b - 2