import java.util.*; import java.math.*; import java.text.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { int a = sc.nextInt(); int b = sc.nextInt(); int ret; if (a < b) { ret = b - 2; } else { ret = 2000000000 - b - 1; } System.out.println(ret); } }