import java.util.Scanner; class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str1 = in.next(); String str2 = in.next(); int A = Integer.parseInt(str1); int B = Integer.parseInt(str2); if(A > B) { int m = 2000000000 - A; int n = A - B - 1; System.out.println(m + n); } if(A < B) { System.out.println(A - 1); } } }