import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int left = sc.nextInt(); int center = sc.nextInt(); int right = 0; if (left < center) { right = center - 2; } else if (left > center) { right = 2000000000 - center - 1; } System.out.println(right); } }