#!/usr/bin/env python3
a, b = map(int,input().split())
if a < b:
    print(b - 2)
elif a > b:
    print(2000000000 - 1 - b)