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: interview

Starter code:

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

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

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


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

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

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


def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n, m = read_int_array()
    if m < 2:
        write(1)
        return
    left = n - m
    write(min(left, m))


main()


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

a, b = map(int, input().split())

if b > a / 2:
	print(a - b)
elif b < 1:
	print(1)
else:
	print(b)

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

main()

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


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

from collections import defaultdict as dd
import math
def nn():
	return int(input())

def li():
	return list(input())

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

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



n, m=mi()


lowend=max(1, m)

highend=n-m

print(min(lowend,highend))


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)

# import sys
# sys.stdin = open("#input.txt", "r")
n,m = list(map(int, input().split()))

if n==m:
	print(0)
elif m<=1 or n-m<=1:
	print(1)
else:
	print(min(m,n-m))


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

n, m = list(map(int, input().split()))
if m * 2 <= n and m != 0:
	print(m)
elif m == 0:
	print(1)
else:
	print(n - m)


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


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


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

if m == n:
    print(0)

elif m == 0 or m == 1:
    print(1)

else:
    m -= 1
    n -= 1
    print(min(m+1, n - m))


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


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