import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); sc.close(); if (n % 2 == 0) { int ans = n / 2; int k1 = 1 + k; int k2 = n + 1 - k; if (k1 < k2) { ans -= (k2 - k1) / 2 - 1; } System.out.println(ans); } else { int k2 = k + 1; if (k % 2 == 0) { k2++; } System.out.println(Math.min(n, k2)); } } }