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(Math.max(b - 2, 0)); } else if (a == b) { System.out.println(0); } else { System.out.println(MAX - b - 1); } } }