# -*- coding: utf-8 -*- a, b = map(int, input().split()) if a < b: print(a-1) else: print(2000000000-a)