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 - left; } System.out.println(right); } }