# -*- coding: utf-8 -*- A, B = map(int, raw_input().split()) if A < B: print B - 2 else: print 2000000000 - 1 - B