import java.util.* import java.util.NoSuchElementException import java.io.IOException import java.util.PriorityQueue import java.util.Arrays import java.util.ArrayList var sc : FastScanner = FastScanner() fun main(args: Array) { var N = sc.nextInt() var K = sc.nextInt() if(K == 0 || K > N) println("0") else { if(N % 2 == 1 && (N + 1) / 2 == K) println((N - 1).toString()) else println((N - 2).toString()) } } class FastScanner { private val `in` = System.`in` private val buffer = ByteArray(1024) private var ptr = 0 private var bufferLength = 0 private fun hasNextByte(): Boolean { if (ptr < bufferLength) { return true } else { ptr = 0 try { bufferLength = `in`.read(buffer) } catch (e: IOException) { e.printStackTrace() } if (bufferLength <= 0) { return false } } return true } private fun readByte(): Int { if (hasNextByte()) return buffer[ptr++].toInt() else return -1 } private fun isPrintableChar(c: Int): Boolean { return 33 <= c && c <= 126 } private fun skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++ } internal operator fun hasNext(): Boolean { skipUnprintable() return hasNextByte() } operator fun next(): String { if (!hasNext()) throw NoSuchElementException() val sb = StringBuilder() var b = readByte() while (isPrintableChar(b)) { sb.appendCodePoint(b) b = readByte() } return sb.toString() } internal fun nextLong(): Long { if (!hasNext()) throw NoSuchElementException() var n: Long = 0 var minus = false var b = readByte() if (b == '-'.toInt()) { minus = true b = readByte() } if (b < '0'.toInt() || '9'.toInt() < b) { throw NumberFormatException() } while (true) { if ('0'.toInt() <= b && b <= '9'.toInt()) { n *= 10 n += (b - '0'.toInt()).toLong() } else if (b == -1 || !isPrintableChar(b)) { return if (minus) -n else n } else { throw NumberFormatException() } b = readByte() } } internal fun nextDouble(): Double { return java.lang.Double.parseDouble(next()) } internal fun nextDoubleArray(n: Int): DoubleArray { val array = DoubleArray(n) for (i in 0..n - 1) { array[i] = nextDouble() } return array } internal fun nextDoubleMap(n: Int, m: Int): Array { val map = arrayOfNulls(n) for (i in 0..n - 1) { map[i] = nextDoubleArray(m) } return map } fun nextInt(): Int { return nextLong().toInt() } fun nextIntArray(n: Int): IntArray { val array = IntArray(n) for (i in 0..n - 1) { array[i] = nextInt() } return array } }