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