import java.io.*; import java.util.*; import java.math.*; class Main { static int len; public static void out (Object o) { System.out.println(o); } public static int solve (int a , int b) { int ret = Math.abs(a - b) - 1; return a < b ? ret + a - 1 : ret + 2000000000 - a; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); out(solve(a , b)); } }