The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...

What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $n$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.

Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $m$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?

Could you help her with this curiosity?

You can see the examples and their descriptions with pictures in the "Note" section.


-----Input-----

The only line contains two integers $n$ and $m$ ($2 \leq n \leq 1000$, $0 \leq m \leq n$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.


-----Output-----

Print a single integer — the maximum number of groups of cats at the moment Katie observes.


-----Examples-----
Input
7 4

Output
3

Input
6 2

Output
2

Input
3 0

Output
1

Input
2 2

Output
0



-----Note-----

In the first example, originally there are $7$ cats sitting as shown below, creating a single group: [Image] 

At the observed moment, $4$ cats have left the table. Suppose the cats $2$, $3$, $5$ and $7$ have left, then there are $3$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining. [Image] 

In the second example, there are $6$ cats sitting as shown below: [Image] 

At the observed moment, $2$ cats have left the table. Suppose the cats numbered $3$ and $6$ left, then there will be $2$ groups remaining ($\{1, 2\}$ and $\{4, 5\}$). It is impossible to have more than $2$ groups of cats remaining. [Image] 

In the third example, no cats have left, so there is $1$ group consisting of all cats.

In the fourth example, all cats have left the circle, so there are $0$ groups.

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
if k == 0:
	print(1)
	exit()
if n >= 2 * k:
	print(k)
else:
	print(n - k)


L = list(map(int, input().split()))
n = int(L[0])
m = int(L[1])
if m == 1:
	print(1)
elif m == 0:
	print(1)
elif m == n:
	print(0)
else:
	L = [2 for i in range(n)]
	for i in range(m):
		to_del = L.index(max(L))
		L[to_del] = -1
		if to_del == 0:
			L[1] -= 1
			L[n - 1] -= 1
		elif to_del == n - 1:
			L[0] -= 1
			L[n - 2] -= 1
		else:
			L[to_del - 1] -= 1
			L[to_del + 1] -= 1
	zero = L.count(0)
	one = int(L.count(1) / 2)
	print(zero + one)


def solve():
	(n, m) = map(int, input().split())
	if m == 0:
		return 1
	return min(m, n - m)
print(solve())


import sys, math, queue
MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
if m == 0:
	print(1)
	exit()
c = [1 for i in range(n)]
i = 0
while m > 0:
	if c[i] == 1:
		c[i] = 0
		m -= 1
		i = (i + 2) % n
	else:
		i = (i + 1) % n
ans = 0
for i in range(n):
	if c[i] == 1 and c[(i + 1) % n] == 0:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
a = ['t'] * n
for i in range(m):
	if i * 2 < n and a[i * 2] == 't':
		a[i * 2] = 'f'
	else:
		ind = a.index('t')
		a[ind] = 'f'
s = ''.join(a)
count = s.strip('f').count('f')
if count != 0 or 't' in s:
	print(count + 1)
else:
	print(count)


(n, m) = map(int, input().split())
if m == 0 or m == 1:
	print(1)
else:
	print(min(n - m, m))


(n, m) = map(int, input().split())
ai = [1] * n
if m == 0:
	print(1)
else:
	for i in range(0, n, 2):
		if m == 0:
			break
		m -= 1
		ai[i] = 0
	for i in range(1, n, 2):
		if m == 0:
			break
		m -= 1
		ai[i] = 0
	num = 0
	for i in range(1, n):
		if ai[i] == 1 and ai[i - 1] == 0:
			num += 1
	print(num)


(n, z) = map(int, input().split())
if z == 0:
	print(1)
else:
	print(min(z, n - z))


(n, m) = [int(x) for x in input().split()]
if m == 0:
	print(1)
elif m <= n / 2:
	print(m)
else:
	print(n - m)


data = [int(i) for i in input().split()]
cats_plots_num = []
cats_leave = 0
for cats in range(1, data[0] + 1, 2):
	if cats_leave == data[0] - data[1]:
		break
	cats_plots_num += [cats]
	cats_leave += 1
if data[1] == 0:
	print('1')
elif data[1] >= len(cats_plots_num):
	print(len(cats_plots_num))
else:
	print(data[1])


from sys import stdin, stdout
(n, m) = [int(x) for x in stdin.readline().split()]
if m == n:
	stdout.write('0\n')
elif m <= 1:
	stdout.write('1\n')
elif n <= 2 * m:
	stdout.write(str(n - m) + '\n')
else:
	stdout.write(str(m) + '\n')


(n, k) = input().split(' ')
n = int(n)
k = int(k)
z = n - k
if n == k:
	print(0)
elif z < k:
	print(z)
elif k == 0:
	print(1)
else:
	print(k)


(n, m) = map(int, input().split())
mark = [1 for _ in range(n)]
i = 0
run = m
while i < n and run != 0:
	mark[i] = 0
	i += 2
	run -= 1
a = ''
for v in mark:
	a += str(v)
b = a.split('0')
count = 0
for v in b:
	if '1' in v:
		count += 1
if m == 1 or m == 0:
	print(1)
else:
	print(count - run)


(N, M) = (int(x) for x in input().split())
A = [i for i in range(1, N + 1)]
if M >= N:
	print(0)
	exit(0)
exhaust = False
i = 0
for _ in range(M):
	A[i] = 0
	if i < N:
		i += 2
		if i >= N:
			exhaust = True
			for (idx, val) in enumerate(A):
				if val != 0:
					i = idx
					break
answer = 0
new_group = True
for (idx, val) in enumerate(A):
	if A[idx] != 0:
		if new_group:
			answer += 1
		new_group = False
	else:
		new_group = True
print(answer)


(n, m) = map(int, input().split(' '))
pairs = n // 2
if n == m:
	print(0)
elif m == 0 or m == 1:
	print(1)
elif m <= pairs:
	print(m)
elif n % 2 and m == pairs + 1:
	print(pairs)
else:
	print(n - m)


(n, m) = (int(i) for i in input().split())
if n == m:
	print(0)
elif m <= 1:
	print(1)
else:
	a = n // 2
	b = n % 2
	if m <= a:
		print(m)
	else:
		if b == 1:
			m -= 1
		r = 2 * a - m
		print(r)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().rstrip().split())
if m == 0:
	print(1)
else:
	print(min(n - m, m))


import math
(n, m) = map(int, input().split())
if m == 0:
	print(1)
elif m <= n - m:
	print(m)
else:
	print(n - m)


(n, m) = map(int, input().split())
nOdd = n + 1 >> 1
nEven = n >> 1
print(max(1, m) if m < nOdd else nEven - m + nOdd)


exec('a, b = [int(i) for i in input().split()]\nif b == 0 and a != 0:\n    print(1)\nelse:\n    print(min(b, a - b))')


import os
import sys

class InputReader:

	def __init__(self):
		self.IN = open('cf.in') if os.path.exists('cf.in') else sys.stdin
		self.tokens = []
		self.index = 0

	def check(self):
		if self.index >= len(self.tokens):
			self.tokens = self.IN.readline().rstrip('\n').split()
			self.index = 0

	def nextToken(self):
		self.check()
		self.index += 1
		return self.tokens[self.index - 1]
reader = InputReader()

def S():
	return reader.nextToken()

def I():
	return int(S())

def F():
	return float(S())
(n, m) = (I(), I())
if m <= 1:
	print(1)
else:
	groups = 1
	groups += min(m, n // 2) - 1
	m -= min(m, n // 2)
	if m > 0:
		groups -= m - n % 2
	print(groups)


(n, m) = map(int, input().split())
print(min(max(m, 1), n - m))


import sys
(n, m) = map(int, input().split())
if m == 0:
	print(1)
	sys.exit()
if m <= n // 2:
	print(m)
else:
	print(n - m)


import math
from fractions import Fraction as frac
MOD = 1000000000.0 + 7

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(case_no):
	(n, m) = map(int, input().split())
	if m == 0:
		print(1)
		exit()
	print(n - max(m, n - m))
t = 1
for i in range(1, t + 1):
	solve(i)


(n, m) = map(int, input().strip().split())
if m == 0:
	print(1)
elif m == n:
	print(0)
else:
	m -= 1
	n -= 1
	nums = [i for i in range(1, n + 1)]
	index = 0
	for i in range(1, n, 2):
		if index >= m:
			break
		nums[i] = 0
		index += 1
	if index == 0:
		print(1)
	else:
		if index >= m:
			ans = index
			if index << 1 < len(nums):
				ans += 1
		else:
			need = m - index
			while need > 0:
				for i in range(len(nums) - 1, -1, -1):
					if nums[i] != 0:
						nums[i] = 0
						break
				need -= 1
			ans = 0
			for i in range(len(nums)):
				if nums[i] != 0:
					ans += 1
		print(ans)


fuckingShit = input().split(' ')
for i in range(len(fuckingShit)):
	fuckingShit[i] = int(fuckingShit[i])
if fuckingShit[1] >= fuckingShit[0] / 2:
	print(fuckingShit[0] - fuckingShit[1])
elif fuckingShit[1] == 0:
	print(1)
else:
	print(fuckingShit[1])


(n, m) = map(int, input().split())
k = n // 2
if m <= k:
	print(max(m, 1))
elif n % 2 == 1:
	print(k - (m - k - 1))
else:
	print(k - (m - k))


X = list(map(int, input().split()))
Sit = [1 for j in range(X[0])]
i = 0
if X[1] == 0:
	print(1)
	exit()
while X[1] != 0:
	while Sit[i] != 1:
		i = (i + 1) % X[0]
	Sit[i] = 0
	X[1] -= 1
	i = (i + 2) % X[0]
Temp = ''
for i in Sit:
	Temp += str(i)
print(Temp.count('01'))


(n, m) = map(int, input().split())
r = [1 for i in range(n)]
for i in range(m):
	pos = 2 * i % n
	if r[pos] == 0:
		pos += 1
		pos %= n
	r[pos] = 0
if r[0] == r[-1] == 1:
	ans = -1
else:
	ans = 0
for e in ''.join(map(str, r)).split('0'):
	if e != '':
		ans += 1
if m == 0:
	print(1)
else:
	print(ans)


(a, b) = map(int, input().split())
if b <= a // 2:
	if b == 0:
		print(1)
	else:
		print(b)
elif b > a // 2:
	if a % 2 == 1:
		print(a // 2 - b + a // 2 + 1)
	else:
		print(a // 2 - b + a // 2)


import sys
from math import ceil
input = sys.stdin.readline
(n, m) = map(int, input().split())
if m > n // 2:
	print(n - m)
else:
	print(max(1, m))


import sys
import collections
import math
import heapq
from operator import itemgetter

def getint():
	return int(input())

def getints():
	return [int(x) for x in input().split(' ')]
(n, m) = getints()
result = 0
if n == 0:
	result = 0
elif m == 0:
	result = 1
else:
	cats = [1] * n
	pos = -2
	for i in range(m):
		pos = (pos + 2) % n
		while cats[pos] == 0:
			pos = (pos + 1) % n
		cats[pos] = 0
	last = cats[-1]
	for val in cats:
		if val and (not last):
			result += 1
		last = val
print(str(result))


in_ = input()
(n, m) = in_.split(' ')
(n, m) = (int(n), int(m))
if m == 0:
	print(1)
elif m > float(n) / 2:
	print(n - m)
else:
	print(m)


from itertools import groupby
(n, m) = map(int, input().split(' '))
arr = [1 for i in range(n)]
c = 0
i = 0
if n == m:
	print(0)
	exit()
inc = 2
while c != m:
	if arr[i] != 0:
		arr[i] = 0
		c += 1
		i += inc
	elif arr[i] == 0:
		i += inc
	if i >= n:
		inc = 1
		i = 0
ans = 0
for (i, j) in groupby(arr):
	if i == 1:
		ans += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
if m == 0:
	print(1)
else:
	print(min(m, n - m))


def main():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	if m == 0:
		print(1)
	elif n == m:
		print(0)
	else:
		di = n - m
		if di <= m:
			print(di)
		else:
			print(m)
main()


(n, m) = list(map(lambda x: int(x), input().split(' ')))
a = [1 for i in range(n)]
s = 0
deleted = False
while m > 0:
	if a[s] == 1 and (not deleted):
		a[s] = 0
		m -= 1
		s += 1
		deleted = True
	else:
		deleted = False
		s += 1
	if s == n:
		s = 0
cnt = 0
new_group = True
for i in a:
	if i > 0:
		if new_group:
			cnt += 1
			new_group = False
	else:
		new_group = True
print(cnt)


(no_of_cats, no_of_cats_left) = map(int, input().split())
l = []
if no_of_cats_left == 0:
	print(1)
elif no_of_cats % 2 == 0:
	if no_of_cats // 2 == no_of_cats_left:
		print(no_of_cats_left)
	elif no_of_cats_left < no_of_cats // 2:
		print(no_of_cats_left)
	else:
		print(no_of_cats - no_of_cats_left)
elif no_of_cats_left <= no_of_cats // 2:
	print(no_of_cats_left)
else:
	print(no_of_cats - no_of_cats_left)


from sys import stdin
(n, m) = map(int, stdin.readline().split())
if m == 0:
	print(1)
elif n == m:
	print(0)
elif m > n // 2:
	print(n - m)
else:
	print(m)


(N, M) = (int(i) for i in input().split())
if M == 0:
	print(1)
elif M * 2 > N:
	print(N - M)
else:
	print(M)


(N, M) = map(int, input().split())
if M == 0:
	print(1)
else:
	print(min(M, N - M))


def main():
	(n, m) = map(int, input().split())
	most = n // 2
	if m <= most:
		print(m + (m == 0))
	else:
		print(most - (m - most - (n & 1)))
main()


(a, b) = map(int, input().split())
if b == 0:
	print(1)
else:
	print(min(a - b, b))


import sys
(n, m) = [int(x) for x in input().split()]
out = 0
if float(m) <= n / 2 and float(m) > 0:
	out = m
elif float(m) > n / 2:
	out = n - m
elif m == 0:
	out = 1
print(out)


m = [*map(int, input().split())]
if m[1] == 0:
	print(1)
elif m[1] == m[0]:
	print(0)
elif m[0] // 2 >= m[1]:
	print(m[1])
elif m[0] // 2 < m[1]:
	print(m[0] - m[1])


I = input
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
(n, m) = IN(I())

def cal(m, n):
	if m == 0:
		return 1
	n -= 1
	m -= 1
	if m >= n // 2:
		return n - m
	return m + 1
print(cal(m, n))


(a, b) = [int(i) for i in input().split()]
l = [1] * a
if b == 0:
	print(1)
else:
	print(min(b, a - b))


(n, m) = map(int, input().split())
ar = [1 for k in range(n)]
ptr = 0
for k in range(m):
	if ptr < n and ar[ptr] == 1:
		ar[ptr] = 0
		ptr += 2
	else:
		for p in range(n):
			if ar[p] == 1:
				ar[p] = 0
				break
ptr = 0
for k in range(n - 1):
	if ar[k + 1] == 1 and ar[k] == 0:
		ptr += 1
print(ptr if m != 0 else 1)


def main():
	(n, m) = map(int, input().split())
	if n > 2:
		if m <= n // 2:
			return max(1, m)
		else:
			return n - m
	elif m == 0:
		return 1
	else:
		return n - m
a = main()
print(a)


(p, q) = list(map(int, input().split()))
if q == 0:
	print(1)
elif p == q:
	print(0)
elif p - q > q:
	print(q)
else:
	print(p - q)


(N, M) = input().split()
N = int(N)
M = int(M)
if N == M:
	print('0')
elif M == 1 or M == 0:
	print('1')
elif N == 2:
	print('1')
else:
	z = [1 for i in range(N)]
	i = 0
	b = 0
	sum = 0
	while b != M:
		if i + 2 > len(z) - 1:
			z[i] = 0
			i = 1
		else:
			z[i] = 0
			i = i + 2
		b = b + 1
	for i in range(N):
		if z[i] == 0:
			pass
		elif i + 1 < len(z):
			if z[i + 1] == 1:
				pass
			else:
				sum = sum + 1
		elif z[0] == 1:
			pass
		else:
			sum = sum + 1
	print(sum)


(n, k) = input().split()
n = int(n)
k = int(k)
if n == k:
	print(0)
elif k == 0:
	print(1)
else:
	half = int(int(n) / 2)
	if n % 2 == 0:
		if half >= k:
			print(k)
		else:
			print(n - k)
	elif half == k or half + 1 == k:
		print(half)
	elif half > k:
		print(k)
	else:
		print(n - k)


(n, m) = map(int, input().strip().split(' '))
if n == m:
	print('0')
elif m == 0 or m == n - 1:
	print('1')
elif n % 2 == 0:
	p = n // 2
	if p == m:
		print(p)
	elif m < p:
		print(m)
	else:
		print(2 * p - m)
elif n % 2 != 0:
	p = n // 2
	if m == p or m == p + 1:
		print(p)
	elif m > p + 1:
		print(2 * p - m + 1)
	elif m < p:
		print(m)


(n, m) = map(int, input().split())
if m == 0 or n - m == 1:
	print(1)
elif n == m:
	print(0)
elif m < 3:
	print(m)
elif n - m < m:
	print(n - m)
else:
	print(m)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, m) = mi()
print(1 if m == 0 else min(n - m, m))


a = input()
i = 0
while a[i] != ' ':
	i = i + 1
b = a[0:i:1]
c = a[i + 1::1]
if int(c) == 0:
	print(1)
else:
	print(min(int(c), int(b) - int(c)))


(N, M) = map(int, input().split())
print(min(max(1, M), N - M))


(n, m) = list(map(int, input().split()))
if m <= 1:
	g = 1
elif m == n:
	g = 0
else:
	g = min(m, n - m)
print(g)


(nre, mre) = list(map(int, input().split()))
if mre == 0:
	print(1)
elif mre <= nre // 2:
	print(mre)
else:
	print(nre - mre)


import sys
input = sys.stdin.readline
for _ in range(1):
	(n, m) = map(int, input().split())
	if m == 0:
		print(1)
		continue
	if n == m:
		print(0)
		continue
	x = n // 2
	e = m - x
	if e > 0:
		if n % 2 == 1:
			e -= 1
		print(x - e)
	else:
		print(min(x, m))


(n, m) = map(int, input().strip().split())
if n == m:
	print(0)
elif m == 0:
	print(1)
else:
	print(min(n - m, m))


vklad = input()
vklad = vklad.split()
myspocet = int(vklad[0])
mysskip = int(vklad[1])
myszostatok = myspocet - mysskip
mysskupina = 0
if myspocet / 2 >= mysskip:
	if mysskip == 0:
		mysskip = 1
	mysskupina = mysskip
	print(mysskupina)
elif myspocet / 2 < mysskip:
	mysskupina = myspocet - mysskip
	print(mysskupina)


def f(n):
	n += 1
	n = str(n)
	cut = len(n)
	for i in n[::-1]:
		if i != '0':
			break
		cut -= 1
	n = int(n[:cut])
	return n
while True:
	try:
		(n, m) = map(int, input().split())
		if n == m:
			print('0')
		elif m == 1 or m == 0:
			print('1')
		elif m < n / 2:
			print(m)
		elif m >= n / 2:
			print(n - m)
	except EOFError:
		break


(x, y) = input().split(' ')
(x, y) = (int(x), int(y))
if y == 0:
	print('1')
elif x - y <= y:
	print(x - y)
elif x - y > y:
	print(y)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, k) = ei()
print(1 if k == 0 else min(k, n - k))


k = [*map(int, input().split())]
z = int(k[0] / 2)
if k[1] <= z:
	if k[1] != 0:
		print(k[1])
	else:
		print(1)
else:
	print(k[0] - k[1])


(n, m) = map(int, input().split())

def max_part(n, m):
	if m > 0:
		if n // 2 == 0:
			if m <= n // 2:
				return m
			else:
				return n - m
		elif m <= (n - 1) // 2:
			return m
		else:
			return n - m
	else:
		return 1
print(max_part(n, m))


(n, m) = input().split()
m = int(m)
n = int(n)
if m <= 1:
	print(1)
else:
	print(min(m, n - m))


(n, m) = [int(i) for i in input().split()]
print(int(1 / 2 * (1 / 2 * (m + 1 + abs(m - 1)) + n - m - abs(1 / 2 * (m + 1 + abs(m - 1)) - n + m))))


inp = input().split(' ')
n = int(inp[0])
m = int(inp[1])
arr = [1] * n
(i, count) = (0, 0)
if m == 0:
	print(1)
else:
	while m != 0:
		arr[i] = 0
		i = i + 2
		m = m - 1
		if i >= n:
			i = 1
	arr.append(arr[0])
	for i in range(0, n):
		if arr[i] == 1 and arr[i + 1] == 1:
			continue
		if arr[i] == 1 and arr[i + 1] == 0:
			count = count + 1
	print(count)


from math import *
(x, y) = map(int, input().split())
if y == 0 or y == 1:
	print(1)
elif x % 2 == 0 and y < x // 2:
	print(y)
elif x % 2 != 0 and y < ceil(x / 2):
	print(y)
else:
	print(x - y)


(n, m) = map(int, input().split())
if n - m == 0:
	print(0)
else:
	k = 1
	l = []
	for i in range(0, n // 2):
		l.append(k)
		k += 1
	if n % 2 != 0:
		h = l[::-1]
		l = [1] + l + h + [0]
	else:
		h = l[::-1]
		l = [1] + l + h[1:] + [0]
	print(l[m])


x = list(map(int, input().split()))
n = x[0]
l = x[1]
if l == 0:
	print(1)
else:
	print(min(l, n - l))


def main():
	(n, m) = (int(x) for x in input().split())
	if n == m:
		print(0)
	elif m <= 1:
		print(1)
	else:
		print(min(m, n - m))
main()


import math
(n, m) = list(map(int, input().lstrip().split()))
if n == m:
	print(0)
elif m == 0:
	print(1)
elif m <= n // 2:
	print(m)
else:
	print(n - m)


R = lambda : map(int, input().split())
(n, k) = R()
a = list('1' * n)
for i in range(0, n, 2):
	if k == 0:
		break
	a[i] = '0'
	k -= 1
for i in range(1, n, 2):
	if k == 0:
		break
	a[i] = '0'
	k -= 1
a = '0' + ''.join(a)
print(a.count('01'))


(n, m) = map(int, input().split())
if m > 1:
	if 2 * m < n:
		print(m)
	else:
		print(n - m)
else:
	print(1)


import collections
(n, m) = map(int, input().split())
groups = collections.defaultdict(int)
groups[n] = 1
for _ in range(m):
	max_group = max(groups.keys())
	if max_group == 2:
		groups[max_group - 1] += 1
	elif max_group > 2 and max_group < n:
		groups[1] += 1
		groups[max_group - 2] += 1
	elif max_group == n:
		groups[max_group - 1] += 1
	groups[max_group] -= 1
	if groups[max_group] == 0:
		del groups[max_group]
nonempty_groups = 0
for (_, group_size) in groups.items():
	if group_size > 0:
		nonempty_groups += group_size
print(nonempty_groups)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		(n, k) = self.next_ints()
		print(1 if k == 0 else min(n - k, k))
Main().solve()


import math
(n, m) = input().split(' ')
n = int(n)
m = int(m)
if m >= math.ceil(n / 2):
	print(int(n / 2 - (m - n / 2)))
elif m == 0:
	print(1)
elif n == m:
	print(0)
else:
	print(m)


(n, m) = [int(i) for i in input().split(' ')]
lines = n
nodes = n
nodes -= m
lines -= m * 2
ans = -1
if m == 0 or m == 1:
	if n == 0:
		ans = 0
	else:
		ans = 1
elif lines <= 0:
	ans = n - m
else:
	ans = nodes - lines
print(ans)


import atexit
import io
import sys
from collections import Counter
(a, b) = map(int, input().split())
if b == 0:
	print(1)
elif b >= a / 2:
	print(a - b)
else:
	print(b)


import math as mm
(n, m) = map(int, input().split())
if m == 0:
	print(1)
elif n % 2 == 0:
	if m <= n // 2:
		print(m)
	else:
		print(n - m)
elif m <= mm.floor(n / 2):
	print(m)
elif m == mm.floor(n / 2) + 1:
	print(m - 1)
else:
	print(n - m)


p = input().rstrip().split(' ')
if int(p[1]) == int(p[0]):
	print(0)
elif int(p[1]) == 0:
	print(1)
else:
	f = int(p[0]) - int(p[1])
	print(min(f, int(p[1])))


(n, m) = input().split()
n = int(n)
m = int(m)
if m <= 1:
	print(1)
elif m >= n / 2:
	print(n - m)
else:
	print(m)


(n, m) = [int(x) for x in input().split()]
if m == 0 or m == 1:
	print('1')
else:
	ans = min(n - m, m)
	print(ans)


def main():
	(n, m) = map(int, input().split())
	if m == 0:
		print(1)
		return
	a = [True] * n
	a[0] = False
	m -= 1
	for p in range(2, n, 2):
		if m == 0:
			break
		a[p] = False
		m -= 1
	for p in range(1, n, 2):
		if m == 0:
			break
		a[p] = False
		m -= 1
	v = sum(a)
	e = sum((x and y for (x, y) in zip(a, a[1:])))
	print(v - e)
main()


inp = str(input())
n = int(inp.split(' ')[0])
m = int(inp.split(' ')[1])
c = n - m
if m == 0:
	print('1')
elif c < m:
	print(c)
else:
	print(m)


from sys import stdin
(n, m) = [int(_) for _ in stdin.readline().strip().split()]
if m == 0:
	print(1)
elif m > n:
	print(0)
else:
	print(min(n - m, m))


(n, m) = map(int, input().split())
if m == n:
	print(0)
	exit()
if m == 1:
	print(1)
	exit()
ans = [i + 1 for i in range(n)]
i = 0
while m:
	if ans[i] != 0:
		ans[i] = 0
		i += 2
		i %= n
		m -= 1
	else:
		i += 1
		i %= n
		ans[i] = 0
		m -= 1
		i += 2
		i %= n
temp = []
for i in range(len(ans)):
	if ans[i]:
		temp.append(ans[i])
total = 1
for i in range(1, len(temp)):
	if temp[i] != temp[i - 1] + 1:
		total += 1
print(total)


(n, m) = map(int, input().split())
A = [i for i in range(n)]
if m == 0:
	print(1)
	exit()
for i in range(0, n, 2):
	A[i] = -1
	m -= 1
	if m == 0:
		break
if m > 0:
	for i in range(1, n, 2):
		A[i] = -1
		m -= 1
		if m == 0:
			break
ans = p = 0
for i in range(n):
	if not p and A[i] != -1:
		ans += 1
		p = 1
	elif p and A[i] == -1:
		p = 0
print(ans)


(n, m) = map(int, input().split())
l = [1] * n
i = 0
for _ in range(m):
	l[i % n] = 0
	i = i + 2
flag = True
if m == 0:
	if n == 0:
		print(0)
	else:
		print(1)
elif n == m:
	print(0)
else:
	c = 0
	for i in range(n - 1):
		if flag:
			if l[i] == 0:
				c = c + 1
				flag = False
		elif l[i] == 1:
			flag = True
	if n % 2 == 0:
		if m >= n / 2:
			print(c - m + int(n / 2))
		else:
			print(c)
	else:
		print(c)


(n, m) = list(map(int, input().split()))
A = [1] * n
idx = 0
for i in range(m):
	while A[idx] == -1:
		idx += 1
	A[idx] = -1
	idx += 2
	idx = idx % n
cnt = 0
i = -1
while i < n:
	i += 1
	if i >= n:
		break
	if A[i] == 1:
		while i < n and A[i] == 1:
			i += 1
		cnt += 1
print(cnt)


x = input()
x = x.split(' ')
cats_attended = int(x[0])
cats_left = int(x[1])
if int(x[1]) == 0:
	if int(x[0]) != 0:
		print(1)
	else:
		print(0)
elif int(x[0]) / int(x[1]) > 2 or (int(x[0]) % int(x[1]) == 0 and int(x[0]) != int(x[1])):
	print(int(x[1]))
else:
	print(int(x[0]) - int(x[1]))


(n, m) = list(map(int, input().split()))
ans = min(max(1, m), n - m)
print(ans)


(n, m) = [int(x) for x in input().split()]
print([n - m, m, 1][(m <= n / 2) * (m > 0) + 2 * (m == 0)])


def go():
	(n, m) = map(int, input().split(' '))
	half = (n + 1) // 2
	if m >= half:
		return n - m
	if m == 0:
		return 1
	return m
print(go())


(n, m) = list(map(int, input().split()))
num_ev = n // 2
if m == 1 or m == 0:
	print(1)
elif n == m:
	print(0)
else:
	if n % 2 == 1:
		num_ev = (n + 1) // 2
	else:
		num_ev = n // 2
	if m >= num_ev:
		print(n - m)
	else:
		print(m)


s = [int(n) for n in input().split()]
j = max(1, s[1])
k = s[0] - s[1]
print(min(j, k))


import math
(n, m) = map(int, input().split())
g = 0
k = math.ceil((n - 1) / 2)
if m == 0 or m == 1:
	g = 1
elif m == n:
	g = 0
elif n / m < 2:
	g = n - m
else:
	g = m
print(g)


[n, m] = list(map(int, input().split(' ')))
if m == n:
	print(0)
	exit(0)
if m == 0 or m == 1:
	print(1)
	exit(0)
print(min(n - m, n // 2, m))


n = input().split()
x = int(n[0])
y = int(n[1])
t = x - y
if t == 0:
	print(0)
elif y == 0:
	print(1)
else:
	bz = 0
	for i in range(1, t + 1):
		p = t
		p_2 = y
		m = 0
		while p > 0 and p_2 != 0:
			p_2 -= 1
			p -= i
			m += 1
		if m > bz:
			bz = m
	print(bz)


a = list(map(int, input().split()))
a[0] = a[0] - a[1]
if a[1] == 0:
	print('1')
elif a[1] >= a[0]:
	print(a[0])
else:
	print(a[1])


(a, b) = input().split(' ')
n = int(a)
m = int(b)
y = n - m
if m == 0:
	print('1')
elif y > m:
	print(m)
else:
	print(y)


from math import *
from itertools import *
(n, m) = map(int, input().split(' '))
ans = 1
ans += max(0, m - 1)
print(min(ans, n - m))


(n, m) = list(map(int, input().strip().split()))
if m >= n / 2:
	print(int(n - m))
else:
	print(max(m, 1))


(n, m) = map(int, input().split())
ans = 1
if m > n // 2:
	print(n - m)
else:
	for i in range(2, m + 1):
		ans += 1
	print(ans)


(n, m) = map(int, input().split())
print(min(n - m, (m > 2) * m + (m == 2) * 2 + (m <= 1)))


ii = lambda : int(input())
mi = lambda : map(int, input().split())
(n, m) = mi()
print(1 if m == 0 else min(n - m, m))


(n, m) = map(int, input().split())
l = [1] * n
i = 0
ignore = True
while m > 0:
	if i == n:
		i = 0
	if l[i] == 1 and ignore:
		ignore = False
	elif l[i] == 1:
		l[i] = 0
		m -= 1
		ignore = True
	i += 1
c = 0
for i in range(1, n):
	if l[i] == 0 and l[i - 1] == 1:
		c += 1
if l[n - 1] == 1 and l[0] == 0:
	c += 1
if set(l) == {1}:
	c = 1
print(c)


def max_groups(n, m):
	if m == 0:
		return 1
	elif n == m:
		return 0
	rem = n - m
	if m < rem:
		return m
	else:
		return rem
(n, k) = list(map(int, input().split()))
print(max_groups(n, k))


import math
(x, y) = map(int, input().split())
if y == 0:
	print(1)
elif x == y:
	print(0)
else:
	m = min(y, x - y)
	print(m)


import math
(n, m) = map(int, input().split())

def main(n, m):
	if m == n:
		return 0
	elif m == n - 1:
		return 1
	elif m == 0 or m == 1:
		return 1
	else:
		required = math.ceil(n / 2)
		if m >= required:
			return math.trunc(n / 2) - (m - required)
		return m
print(main(n, m))


from sys import stdin, stdout
for _ in range(1):
	(n, k) = list(map(int, stdin.readline().split()))
	if k == 0:
		print(1)
	elif k <= n // 2:
		print(k)
	else:
		print(n - k)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
(n, m) = mi()
if m == 0:
	print(1)
elif n == m:
	print(0)
elif m <= n // 2:
	print(m)
else:
	print(n - m)


(n, m) = map(int, input().split())
t = [True] * n
j = 0
for i in range(1, n, 2):
	if j == m:
		break
	t[i] = False
	j += 1
for i in range(n):
	if j == m:
		break
	if t[i]:
		t[i] = False
		j += 1
i = 0
c = 0
while i < n:
	if t[i]:
		c += 1
		while i < n and t[i]:
			i += 1
	else:
		i += 1
if t[0] and t[-1] and (False in t):
	c -= 1
print(c)


def convert(string):
	return string.split(sep=None, maxsplit=-1)

def toint(lst):
	result = []
	for i in lst:
		result.append(int(i))
	return result
s = toint(convert(input()))
n = s[0]
m = s[1]
if n == m:
	print(0)
elif m == 0 or m == 1:
	print(1)
elif n - m > m:
	print(m)
else:
	print(n - m)


from math import ceil
(n, m) = map(int, input().split())
if m == 0 or m == 1:
	print('1')
elif n == m:
	print('0')
else:
	n -= 3
	m -= 2
	if n == m:
		print('1')
	elif n < 2 * m:
		print(n - m + 1)
	elif n == 2 * m:
		print(1 + m)
	elif n > 2 * m:
		print(m + 2)


(a, b) = input().strip().split(' ')
(a, b) = [int(a), int(b)]
if b == 0:
	print(1)
if b != 0:
	if a < 2 * b:
		print(a - b)
	else:
		print(b)


def solve():
	l = list(map(int, input().split()))
	if l[1] > 0 and l[0] > 3:
		print(min(l[0] - l[1], l[1]))
	elif l[1] == 0:
		print(1)
	elif l[1] == l[0]:
		print(0)
	else:
		print(1)
solve()


str = input().split(' ')
n = int(str[0])
m = int(str[1])

def calc(n, m):
	if m == 0:
		return 1
	return min(m, n - m)
print(calc(n, m))


(n, m) = map(int, input().split())

def qw(n, m):
	if m == n:
		print(0)
		return
	if m == 0 or m == 1:
		print(1)
		return
	if 2 * m > n:
		m = n - m
	print(m)
qw(n, m)


import os
import sys

def solve():
	(n, m) = map(int, input().split())
	print(min(m, n - m) if m != 0 else 1)
solve()


from sys import stdin, setrecursionlimit
from bisect import bisect_right
setrecursionlimit(15000)
(n, m) = list(map(int, stdin.readline().split()))
if m > n // 2:
	print(n - m)
else:
	if m == 0:
		print(1)
		exit()
	count = 1
	for i in range(1, n + 1, 2):
		if m == 0:
			break
		count += 1
		m -= 1
	print(count - 1)


(n, m) = [int(t) for t in input().split(' ')]
remaining = n - m
if m > remaining:
	print(remaining)
elif m == 0:
	print(1)
else:
	print(m)


import io
import os
from collections import defaultdict
from sys import stdin, stdout
from math import gcd

def main():
	(n, m) = map(int, input().split())
	if m == 0:
		print(1 if n > 0 else 0)
	elif m <= n // 2:
		print(m)
	else:
		print(n - m)
main()


(n, m) = list((int(a) for a in input().split()))
if m == 0 or m == 1:
	print(1)
elif m == n:
	print(0)
else:
	f = 0
	while n > 2 and m > 0:
		m -= 1
		n -= 2
		f += 1
	if m > 0:
		print(f - m + n)
	else:
		print(f)


import sys
import math
import bisect

def solve(n, m):
	if n == m:
		return 0
	if m == 0 or m == 1:
		return 1
	return min(m, n - m)

def main():
	(n, m) = map(int, input().split())
	print(solve(n, m))
main()


(n, m) = map(int, input().split())
if m == n:
	print(0)
	quit()
elif m == 0:
	print(1)
	quit()
m -= 1
if m == 0:
	print(1)
	quit()
s = 0
if n % 2 == 0:
	s = n - 1 - 3
	s //= 2
	s += 1
else:
	s = n - 3
	s //= 2
	s += 1
rem = n - 1 - s
if m >= s:
	m -= s
	print(rem - m)
else:
	x = 3
	ans = 0
	while x <= n and m > 0:
		x += 2
		ans += 1
		m -= 1
	ans += 1
	print(ans)


(n, m) = map(int, input().split())
if not m:
	print(1)
else:
	print(min(m, n - m))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

def nninp():
	return map(int, input().split())

def llinp():
	return list(map(int, input().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
(n, m) = nninp()
if m == 0:
	p(1)
else:
	print(min(m, n - m))


import sys

def cat_circle(n, m):
	pos = ['Sitting'] * n
	while m > 0:
		is_leave = False
		leave_pos = None
		for i in range(n):
			if pos[i] is not None:
				left = (i - 1 + n) % n
				right = (i + 1) % n
				if pos[left] == 'Sitting' and pos[right] == 'Sitting':
					is_leave = True
					leave_pos = i
					break
		if not is_leave:
			for i in range(n):
				if pos[i] is not None:
					left = (i - 1 + n) % n
					right = (i + 1) % n
					if pos[left] is None and pos[right] == 'Sitting':
						is_leave = True
						leave_pos = i
						break
		if not is_leave:
			leave_pos = pos.index('Sitting')
		pos[leave_pos] = None
		m -= 1
	result = 0
	is_grouping = False
	for i in range(n):
		if pos[i] is None:
			if is_grouping:
				is_grouping = False
			else:
				continue
		elif pos[i] == 'Sitting':
			if is_grouping:
				continue
			else:
				result += 1
				is_grouping = True
	return result - 1 if pos[0] == pos[n - 1] == 'Sitting' and None in pos else result
(n, m) = map(int, input().split())
print(cat_circle(n, m))


import sys
(n, m) = sys.stdin.readline().split()
n = int(n)
m = int(m)
if m == 0:
	print('1')
else:
	print(f'{min(m, n - m)}')


(a, b) = map(int, input().split())
print(min(a - b, max(1, b)))


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
(a, b) = viread()
if b == 0:
	print(1)
	exit()
if a < 2 * b:
	print(a - b)
else:
	print(b)


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	(a, b) = MI()
	c = a >> 1
	if a == b:
		print(0)
	elif b <= 1 or a - b == 1:
		print(1)
	elif b == 2:
		print(2)
	elif b <= c:
		print(b)
	else:
		print(a - b)
main()


import collections, heapq, sys
(n, m) = map(int, sys.stdin.readline().rstrip().split(' '))
if m == 0:
	print(1)
else:
	print(min(m, n - m))


from numbers import Number
import math
fuck = None
input2 = None
s = None
inputs = None
i = None
n = None
m = None
answer = None

def text_prompt(msg):
	try:
		return raw_input(msg)
	except NameError:
		return input(msg)
input2 = text_prompt('')
inputs = input2.split(' ')
n = int(inputs[0])
m = int(inputs[1])
if n <= m:
	answer = 0
elif m == 0:
	answer = 1
else:
	if n < m * 2:
		m = n - m
	answer = m
print(answer)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())
(n, k) = f(2)
t = min(k, n - k)
if t == 0:
	if k == 0:
		print(1)
	else:
		print(0)
else:
	print(t)


(n, m) = [int(i) for i in input().split(' ')]

def helper(n, m):
	if m <= 1:
		return 1
	if n == m:
		return 0
	return min(m, n - m)
print(helper(n, m))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	(n, m) = LI()
	t = max(m, 1)
	u = n - m
	return min(t, u)
print(main())


K = list(map(int, input().strip().split()))
n = K[0]
m = K[1]
if m >= n / 2:
	print(n - m)
elif m == 0:
	print(1)
else:
	print(m)


(n, m) = list(map(int, input().split()))
if m == 0:
	print(1)
else:
	ans = min(m, n - m)
	print(ans)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
if m <= 1:
	stdout.write('1\n')
elif m > n // 2:
	stdout.write(str(n - m) + '\n')
else:
	stdout.write(str(m) + '\n')


from sys import stdin
from collections import Counter, defaultdict, deque
from math import sqrt, factorial, log10, log, floor, ceil
from itertools import permutations, combinations, combinations_with_replacement, product
input = stdin.readline

def li():
	return list(map(int, input().split()))

def lis():
	return list(map(str, input().split()))

def mp():
	return map(int, input().split())

def inp():
	return int(input())

def inps():
	return str(input().strip())

def pr(n):
	return stdout.write(str(n) + '\n')

def primes(pmax):
	D = {}
	q = 2
	while q <= pmax:
		if q not in D:
			yield q
			D[q * q] = [q]
		else:
			for p in D[q]:
				D.setdefault(p + q, []).append(p)
			del D[q]
		q += 1

def gcd(i, j):
	while j > 0:
		(i, j) = (j, i % j)
	return i
INF = float('inf')

def solve():
	(n, m) = mp()
	print(min(m, n - m) if m > 0 else 1)
t = 1
for i in range(t):
	solve()


def gns():
	return [int(x) for x in input().split()]

def gn():
	return int(input())
(n, m) = gns()
if n == 1 and m == 0:
	print(1)
	quit()
if n == 1 and m == 1:
	print(0)
	quit()
if m == 0:
	print(1)
	quit()
n -= 1
m -= 1
if m < n // 2:
	print(m + 1)
else:
	print(n - m)


def main():
	(n, m) = map(int, input().split())
	if m == 1 or m == 0:
		print(1)
		return
	if m <= n // 2:
		print(m)
	else:
		print(n - m)
main()


(n, m) = list(map(int, input().split()))

def do():
	if n == m:
		return 0
	if m == 0:
		return 1
	if m < n / 2:
		return m
	else:
		return n - m
print(do())


(x, y) = map(int, input().split())
k = x % 2
x -= k
m = x // 2
if y > m:
	y -= k
if y <= 1:
	print(1)
elif y <= m:
	print(y)
else:
	print(2 * m - y)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = 1
	for _ in range(t):
		(n, m) = num()
		if m == 0:
			print(1)
			continue
		if m == n:
			print(0)
			continue
		if n % 2 == 0:
			ff = n // 2
			if m <= ff:
				print(m)
			else:
				print(n - m)
		else:
			ff = n // 2
			if m <= ff:
				print(m)
			else:
				print(n - m)
solve()


import sys
(n, m) = map(int, input().split())
if m == 1 or m == 0:
	print(1)
	sys.exit()
if m == n:
	print(0)
	sys.exit()
else:
	k = min(m, n - m)
	print(k)


import math
(n, m) = map(int, input().strip().split())
if m == 0:
	print(1)
elif m == n:
	print(0)
else:
	(mid1, mid2) = (m // 2, math.ceil(m / 2))
	gp = n // 2
	if m <= gp:
		print(m)
	elif m > gp:
		print(n - m)
	else:
		print(gp)


(n, m) = [int(x) for x in input().split(' ')]
if m == n:
	print(0)
elif m == 0:
	print(1)
else:
	middle = [n // 2]
	if n % 2 == 1:
		middle.append(middle[0] + 1)
	if m not in middle:
		if m > middle[-1]:
			print(middle[0] - abs(m - middle[-1]))
		else:
			print(m)
	else:
		print(middle[0])


def f(l):
	(n, m) = l
	if m < 2:
		return 1
	return min(m, n - m)
l = list(map(int, input().split()))
print(f(l))


b = input().split()
(n, m) = (int(b[0]), int(b[1]))
if m == 0 or m == 1 or m == n - 1:
	a = 1
elif m == n:
	a = 0
elif m == 2:
	a = 2
else:
	a = min([m, n - m])
print(a)


(a, b) = map(int, input().split())
if b < 2:
	print(1)
	exit()
print(min(b, a - b))


try:
	(a, b) = map(int, input().split())
	print(min(a - b, max(1, b)))
except:
	print(a)
	print(b)


nm = list(map(int, input().rstrip().split()))
n = nm[0]
m = nm[1]
while True:
	if m == 0:
		print(1)
		break
	if m == n:
		print(0)
		break
	if m <= int(n / 2):
		print(m)
		break
	else:
		print(n - m)
		break


def main():
	(n, m) = map(int, input().split())
	print(1 if m == 0 else min(m, n - m))
main()


(n, m) = map(int, input().split())
l = [1] * n
if n <= m:
	print(0)
elif m == 0 or m == 1:
	print(1)
elif m <= n // 2 and n % 2 == 0:
	print(m)
elif m <= n // 2 + 1 and n % 2 == 1:
	if m == n // 2 + 1:
		print(m - 1)
	else:
		print(m)
else:
	p = m - n // 2
	if n % 2 == 1:
		print(n // 2 - p + 1)
	else:
		print(n // 2 - p)


arr = input()
(N, M) = [int(x) for x in arr.split(' ')]
if M * 2 >= N:
	print(N - M)
elif M == 0:
	print(1)
else:
	print(M)


(n, m) = map(int, input().split())
n2 = n // 2
if m in (0, 1) or n - m == 1:
	print(1)
elif n - m == 0:
	print(0)
elif n >= m * 2:
	print(m)
elif n2 < m:
	print(n % m)


(n, m) = map(int, input().strip().split())
if m == 0:
	print(1)
else:
	maxgroup = n // 2
	print(min(maxgroup, n - m, m))


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, m) = mi()
a = [*range(n)]
v = 0
if m > 0:
	for i in range(0, n, 2):
		if m > 0:
			a[i] = -1
			m -= 1
	if m > 0:
		for i in range(1, n, 2):
			if m > 0:
				a[i] = -1
				m -= 1
elif m == 0:
	v = 1
for i in range(n):
	if i != n - 1 and a[i] == -1 and (a[i + 1] != -1):
		v += 1
print(v)


(n, m) = [int(x) for x in input().split()]
cuts = min(n // 2, m)
grps = max(1, cuts)
rem = max(0, m - cuts - n % 2)
print(max(0, grps - rem))


def cat_soup(n, m):
	if m == 0:
		return 1
	return min(m, n - m)
(a, b) = [int(i) for i in input().split()]
print(cat_soup(a, b))


cats = lambda x, y: min(y, x - y) if y > 0 else 1
(x, y) = input().split()
print(cats(int(x), int(y)))


_0x23 = 0
_ = list(map(int, input().split()))
if _[1] == 0:
	print(1)
elif _[0] == _[1]:
	print(0)
else:
	print(min(_[1], _[0] - _[1]))


(n, m) = input().split()
(n, m) = (int(n), int(m))
if m == 0:
	print(1)
	exit(0)
if m == n:
	print(0)
	exit(0)
if m <= n / 2:
	print(m)
	exit(0)
print(n - m)


try:
	(n, m) = list(map(int, input().split(' ')))
	a = [int(i) for i in range(1, n + 1)]
	if m == 0:
		print(1)
	elif m == n:
		print(0)
	else:
		k = 0
		for i in range(0, len(a), 2):
			if k < m:
				a[i] = 0
				k += 1
			else:
				break
		if k == m:
			k = k
		else:
			for i in range(1, len(a), 2):
				if k < m:
					a[i] = 0
					k += 1
				else:
					break
		ink = [i for (i, x) in enumerate(a) if x == 0]
		c = 0
		for i in range(0, len(ink) - 1):
			if ink[i + 1] - ink[i] >= 2:
				c += 1
		if a[len(a) - 1] == 0:
			print(c)
		else:
			print(c + 1)
except:
	pass


(n, m) = map(int, input().strip().split())
import math
if n - m <= n // 2:
	print(n - m)
elif n % 2 == 0:
	g = n // 2
	for k in range(n // 2 + 1, n - m + 1):
		if g > 1:
			g = g - 1
	print(g)
else:
	g = n // 2
	for k in range(n // 2 + 2, n - m + 1):
		if g > 1:
			g = g - 1
	print(g)


(n, m) = input('').split(' ')
n = int(n)
m = int(m)
s = []
for i in range(1, n + 1):
	s.append(i)
i = 0
count = 0
if n % 2 == 0:
	while i != 2 * m:
		if count == m:
			break
		count += 1
		s[i] = 0
		if i == len(s) - 2:
			i = -1
		i += 2
else:
	while i != 2 * m:
		if count == m:
			break
		count += 1
		s[i] = 0
		if i == len(s) - 1:
			i = -1
		i += 2
n = len(s)
c = 0
for j in range(1, n):
	if s[j - 1] == 0 and s[j] != 0:
		c += 1
if m == 0:
	c = 1
if n == m:
	c = 0
print(c)


(n, k) = map(int, input().split())
if k == 0:
	print(1)
elif n // k > 1:
	print(k)
else:
	print(n - k)


(n, m) = map(int, input().split())
k = n - m
if m == 0:
	print(1)
elif m == n:
	print(0)
elif m > k:
	print(k)
elif k >= m:
	print(m)


(n, m) = [int(i) for i in input().split()]
print(max(1, min(n - m, m)) - (m == n))


(n, m) = list(map(int, input().split()))

def groups_cnt(n, m):
	if m == 0:
		return print(1)
	elif m <= int(n / 2):
		return print(m)
	else:
		return print(n - m)
groups_cnt(n, m)


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, m) = map(int, input().split())
	if m == 0:
		print(1)
	elif m < (n + 1) // 2:
		print(m)
	else:
		print(n - m)
main()


from collections import deque
from math import log, sqrt, ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
(n, m) = mi()
if m <= 1:
	print('1')
else:
	print(min(m, n - m))


(a, b) = input().split()
total = int(a)
left = int(b)
remain = total - left
group = 0
if remain <= left:
	group = remain
elif remain > left:
	if remain != 0 and left == 0:
		group = 1
	else:
		group = left
print(group)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
li = []
for i in range(0, n):
	li.append(1)
i = 1
t = m
while m:
	if i < n:
		li[i] = 0
	else:
		if n % 2 != 0:
			i = i - n
		else:
			i = i - (n + 1)
		li[i] = 0
	i = i + 2
	m = m - 1
c = 0
for i in range(0, n - 1):
	if li[i] == 0 and li[i + 1] == 1:
		c = c + 1
if li[0] == 1 and li[n - 1] == 0:
	c = c + 1
if t == 0:
	c = 1
print(c)


def main():
	(n, m) = list(map(int, input().strip().split()))
	max_group = n
	count = 1
	for r in range(1, m + 1):
		if r == 1:
			max_group -= 1
			continue
		if max_group >= 3:
			max_group -= 2
			count += 1
		elif max_group == 2:
			max_group = 1
		elif max_group < 2:
			count -= 1
	print(count)
main()


(n, m) = map(int, input().split())
a = ['a'] * (n + 1)
a[0] = 1
a[-1] = 0
i = 1
while i < n:
	if n / 2 - 0.51 <= i <= n / 2 + 0.51:
		a[i] = n // 2
		i += 1
	elif i < n / 2:
		a[i] = i
		i += 1
	else:
		a[i] = n - i
		i += 1
print(a[m])


(n, m) = map(int, input().split())
if m == 0:
	print(1)
	exit(0)
ot = 0
if n % 2 == 0:
	ot += min(n // 2, m)
	if m > n // 2:
		ot -= m - n // 2
else:
	ot += min(n // 2, m)
	if m > n // 2:
		if m - n // 2 - 1 > 0:
			ot -= m - n // 2 - 1
print(ot)


import heapq
(n, m) = map(int, input().split())
h = []
heapq.heappush(h, -n + 1)
for i in range(m - 1):
	k = heapq.heappop(h)
	if k < -2:
		heapq.heappush(h, k + 2)
		heapq.heappush(h, -1)
	elif k == -2:
		heapq.heappush(h, -1)
print(len(h))


def eating_soup():
	cats = list(map(int, input().split()))
	if cats[0] == cats[1] or cats[0] == 0:
		return 0
	table = [i for i in range(1, cats[0] + 1)]
	i = 0
	while cats[1] > 0:
		table.pop(i)
		i += 1
		cats[1] -= 1
		if i >= len(table):
			i = 0
	output = 0
	for i in range(len(table)):
		if i + 1 < len(table):
			if table[i + 1] - 1 != table[i]:
				output += 1
	return output + 1
A = eating_soup()
print(A)


(cats, left) = [int(number) for number in input().split()]
maxi = cats - left
if left == 0:
	print(1)
elif left < maxi:
	print(left)
else:
	print(maxi)


import math

def main():
	(n, m) = map(int, input().split())
	if m == 0:
		print(1)
		return
	if m < math.ceil(n / 2):
		print(m)
	else:
		print(n - m)
main()


from sys import stdin, stdout
(n, m) = map(int, input().split())
if m == 0:
	print(1)
elif m < n / 2:
	print(m)
else:
	print(n - m)


(n, m) = map(int, input().split())
if m <= 1:
	print(1)
	return
print(min(m, n - m))


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
(n, m) = li()
if m > n // 2:
	m -= n // 2
	ans = (n + 1) // 2
	ans -= m
else:
	ans = m if m else 1
print(ans)


def compute_soup(n, m):
	if m == 0:
		return 1
	if n % 2 == 0:
		if m <= n / 2:
			return m
		else:
			return n - m
	elif m < n / 2:
		return m
	elif m == (n + 1) / 2:
		return m - 1
	else:
		return n - m
(n, m) = [int(i) for i in input().split()]
print(compute_soup(n, m))


(n, m) = map(int, input().split())
if m == 0:
	print('1')
else:
	k = int(n / 2 - abs(n / 2 - m))
	print(k)


(n, m) = (int(i) for i in input().split())
if m > n // 2:
	print(n - m)
elif m:
	print(m)
else:
	print(1)


(n, m) = map(int, input().split())
best = n // 2
if m > best:
	if n % 2:
		print(2 * best - m + 1)
	else:
		print(2 * best - m)
else:
	print(max(m, 1))


(n, m) = map(int, input().split())
CAN0 = n - m
CAN1 = max(1, m)
print(min(CAN0, CAN1))


def solve():
	(N, M) = map(int, input().split())
	if M < 2:
		print(1)
		return
	print(M if M <= N // 2 else N - M)
solve()


l1 = [int(x) for x in input().split()]
n = l1[0]
left = l1[1]
if left == 0:
	groups = 1
elif left <= int(n / 2):
	groups = left
else:
	groups = n - left
print(groups)


import sys
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
(n, m) = map(int, input().split())
if m == 0 or m == 1:
	print(1)
	exit()
if m >= n:
	print(0)
	exit()
if n / m >= 2:
	print(m)
else:
	print(n % m)


import math

def inp_n():
	return int(input())

def inp_list():
	return list(map(int, input().split()))

def inp_mul_num():
	return map(int, input().split())

def is_odd(n):
	if n & 1:
		return True
	return False
(n, m) = inp_mul_num()
l = n // 2
if n % 2 == 0:
	if m >= l:
		print(n - m)
	elif m == 0:
		print(1)
	else:
		print(m)
elif m == 0:
	print(1)
elif math.ceil(n // 2) == m or n // 2 == m:
	print(n // 2)
elif m >= l:
	print(n - m)
else:
	print(m)


import sys

def res(n, m):
	if m == 0:
		print('1')
		return
	if m <= n / 2:
		print(m)
	else:
		print(n - m)
(n, m) = map(int, input().split())
res(n, m)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	elif k == 0:
		print(1)
	elif k <= n // 2:
		print(k)
	else:
		rem = k - n // 2
		if n % 2 != 0:
			rem -= 1
		print(n // 2 - rem)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = list(map(int, input().split()))
n = t[0]
p = t[1]
odd = p
s = [1] * n
for i in range(1, n, 2):
	if odd != 0:
		s[i] = 0
		odd = odd - 1
even = odd
for i in range(0, n, 2):
	if even != 0:
		s[i] = 0
		even = even - 1
sum_i = []
counter = 0
for i in range(0, n):
	if s[i] == 1:
		sum_i.append(counter)
	else:
		counter = counter + 1
pos = len(set(sum_i))
if s[0] == s[n - 1] and s[0] == 1:
	if p > 0:
		pos = pos - 1
		print(pos)
	else:
		print(pos)
else:
	print(pos)


(n, m) = [int(x) for x in input().split()]
if m == 0:
	print(1)
	exit(0)
if m == n:
	print(0)
	exit(0)
if m <= n // 2:
	print(m)
	exit(0)
ans = n // 2
m -= n // 2
ans -= m
print(ans + n % 2)


(n, m) = list(map(int, input().split()))

def generator(n, last):
	if last == n - 1:
		return 1
	if last == n - 2:
		return 1
	else:
		return last + 2
ar = [1 for _ in range(n)]
left = 0
cur_x = 0
if n == 2:
	if m == 0:
		print(1)
	elif m == 1:
		print(1)
	else:
		print(0)
else:
	while left < m:
		if ar[cur_x] == 1:
			ar[cur_x] = 0
			left += 1
		cur_x = generator(n, cur_x)
	total = 0
	is_active = False
	for i in range(len(ar)):
		if ar[i] == 1 and (not is_active):
			is_active = True
		if ar[i] == 0 and is_active:
			total += 1
			is_active = False
	if is_active:
		total += 1
	print(total)


import sys
a = sys.stdin.readline().strip().split()
(n, m) = (int(a[0]), int(a[1]))
count = 0
if n - m < m:
	count = n - m
elif m == 0:
	count = 1
else:
	count = m
print(count)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007
(n, m) = li()
if m == 0:
	print(1)
else:
	print(min(m, n - m))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('C:/Users/njhab/Desktop/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(n, m) = map(int, sys.stdin.readline().split(' '))
	val = n // 2
	ans = 0
	if val >= m:
		ans = max(1, m)
	else:
		ans = n - m
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(n, m) = map(int, input().split())
small = 0
for i in range(m):
	if i == 0:
		n -= 1
		if n == 1:
			small += 1
			n -= 1
		continue
	if n != 0:
		small += 1
		n -= 2
		if n == 1:
			small += 1
			n -= 1
			continue
	else:
		small -= 1
print(small + (n > 0))


(n, m) = map(int, input().split())
if m == 0:
	print(1)
else:
	a = []
	for i in range(n):
		a.append(1)
	j = 0
	for i in range(m):
		flag = 1
		while flag != 0:
			if a[j % n] == 1:
				a[j % n] = 0
				j += 2
				flag = 0
			else:
				j += 1
	groups = 0
	for i in range(1, n):
		if a[i - 1] == 0 and a[i] == 1:
			groups += 1
	print(groups)


(n, k) = map(int, input().split())
m = 0
m1 = n
if k <= 1:
	print(1)
else:
	while (m1 > 1) & (k > 0):
		m1 -= 2
		k -= 1
		m += 1
		n -= 1
	if k == 0:
		print(m)
	elif m1 == 0:
		print(m - k)
	else:
		print(m - k + 1)


(n, m) = input().split()
n = eval(n)
m = eval(m)
if m == 0:
	print(1)
elif n == m:
	print(0)
elif m < n - m:
	print(m)
else:
	print(n - m)


from random import random
import math
import re
import fractions
(N, M) = map(int, input().split(' '))
if M == 0:
	print(1)
else:
	print(min(N - M, M))


S = input().split()
N = int(S[0])
M = max(int(S[1]), 1)
if M > N // 2:
	answer = N - M
else:
	answer = M
print(answer)


Input = lambda : map(int, input().split())
(n, m) = Input()
if m == 0:
	print(1)
	exit()
Best_M_for_Group = n - n // 2
if m == Best_M_for_Group:
	print(n // 2)
elif m < Best_M_for_Group:
	y = Best_M_for_Group - m
	print(n // 2 - y + n % 2)
else:
	y = m - Best_M_for_Group
	print(n // 2 - y)


import math
(a, b) = map(int, input().split())
if b == 0:
	print(1)
elif a == b:
	print(0)
elif math.ceil(a / 2) > b:
	print(b)
else:
	print(a - b)


R = lambda : map(int, input().split())
(n, m) = R()
print(min(n - m, max(m, 1)))


def main():
	s = [int(x) for x in input().split()]
	n = s[0]
	m = s[1]
	if n > m > 1:
		odd = n // 2
		if n % 2 == 1:
			odd += 1
		if odd > m:
			ans = m
		else:
			ans = n - odd - (m - odd)
	elif m <= 1:
		ans = 1
	else:
		ans = 0
	print(ans)
main()


(n, m) = map(int, input().split())
calc = 0
n1 = n
for i in range(m):
	if i < (n1 + 1) // 2 and n != 1:
		n -= 2
		calc += 1
	elif i >= (n1 + 1) // 2:
		calc -= 1
print(calc + (1 if m == 0 else 0))


(n, m) = [int(i) for i in input().strip().split(' ')]

def calc(n, m):
	if m == 0:
		return 1
	if m == 1:
		return 1
	mid = n // 2
	if m <= mid:
		return m
	return n - m
print(calc(n, m))


input_string = input()
array = input_string.split()
n = int(array[0])
m = int(array[1])
if m == 0:
	print(1)
elif n - m <= m:
	print(n - m)
else:
	print(m)


gi = lambda : list(map(int, input().strip().split()))
(n, m) = gi()
if m <= 1:
	print(1)
	exit()
m -= 1
n -= 1
if m < n // 2:
	print(m + 1)
	exit()
ans = n
ans -= min(m, n // 2)
m -= min(m, n // 2)
ans -= m
print(ans)


(n, m) = [int(k) for k in input().split()]
if m == 1 or m == 0:
	print(1)
elif n >= 2 * m:
	print(m)
else:
	print(n - m)


(n, m) = map(int, input().strip().split())
h = n // 2
ans = 0
cur = 0
for i in range(1, min(m, h) + 1):
	ans += 1
	cur += 1
if m > h and n % 2:
	cur += 1
if m > cur:
	for i in range(cur + 1, m + 1):
		ans -= 1
if m == 0:
	print(1)
else:
	print(ans)


(n, m) = [int(i) for i in input().split()]
if m == 0:
	print(1)
	exit(0)
norm = n // 2
should = n - norm
if n % 2 == 1:
	should -= 1
	if m > norm:
		norm += 1
res = should - abs(m - norm)
print(res)


(v1, v2) = map(int, input().split())

def khabib(n, m):
	if m == n:
		print(0)
		return
	elif m == 0 or m == 1:
		print(1)
		return
	elif 2 * m > n:
		m = n - m
	print(m)
khabib(v1, v2)


(n, m) = map(int, input().split())
if m == 0:
	m += 1
if n // 2 >= m:
	print(m)
	exit()
k = n // 2
m -= n // 2
if n % 2:
	m -= 1
print(max(0, k - m))


(n, m) = map(int, input().split())
if m <= 1:
	print('1')
elif n == m:
	print('0')
else:
	count = 0
	l = list(range(1, n + 1))
	i = 0
	while i <= n - 1:
		l[i] = 0
		i += 2
		m -= 1
		if m == 0:
			break
	j = 0
	for i in range(1, n):
		if l[j] == l[i]:
			count += len(l[j:i + 1]) - 2
			j = i
	if l[n - 1] != 0:
		count += 1
	if m == 0:
		print(count)
	else:
		print(count - m)


kk = lambda : map(int, input().split())
(n, m) = kk()
print(n - m if m * 2 > n else max(m, 1))


def int_get():
	s = input()
	l = len(s)
	integ = []
	i = 0
	while i < l:
		s_int = ''
		a = s[i]
		while '0' <= a <= '9':
			s_int += a
			i += 1
			if i < l:
				a = s[i]
			else:
				break
		i += 1
		if s_int != '':
			integ.append(int(s_int))
	return integ

def kitten_check(kitten, upsent_kitten):
	i = 0
	kitten = int(kitten)
	upsent_kitten = int(upsent_kitten)
	if kitten - upsent_kitten == 0:
		print(0)
		return
	if upsent_kitten == 0 or upsent_kitten == 1:
		print(1)
		return
	print(min(upsent_kitten, kitten - upsent_kitten))
	return
integ = int_get()
kitten_check(integ[0], integ[1])


from math import floor, ceil
(n, m) = map(int, input().split())
hash = {}
for i in range(1, n + 1):
	hash[i] = False
count = 0
ans = 1
flag = 0
for i in range(1, n + 1, 2):
	if count < m:
		count += 1
		hash[i] = True
		if flag != 0:
			ans += 1
		if count % 2 == 0 and flag == 0:
			ans += 1
			flag = 1
if count != m:
	count += 1
if m <= floor(n / 2) and n != m:
	print(ans)
else:
	print(n - m)