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