One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.

Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.

Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.

More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that $|c - a|<|c - m|$ is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).


-----Input-----

The first line contains two integers n and m (1 ≤ m ≤ n ≤ 10^9) — the range of numbers in the game, and the number selected by Misha respectively.


-----Output-----

Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.


-----Examples-----
Input
3 1

Output
2
Input
4 3

Output
2


-----Note-----

In the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.

In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less.

Difficulty: EASY
Tags: Constructive algorithms

Implementation

Greedy algorithms

Game theory

Mathematics
Skill types: Greedy algorithms

Starter code:

Solutions:
from functools import cmp_to_key

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

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

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def printlist(l):
	print(''.join([str(x) for x in l]))

def listring(l):
	return ''.join([str(x) for x in l])
(n, m) = mp()
if n == 1:
	print(1)
	exit()
if n == 2:
	print(3 - m)
	exit()
if n % 2 == 0:
	a = n // 2
	if a == m:
		print(a + 1)
	elif a < m:
		print(m - 1)
	else:
		print(m + 1)
else:
	a = n // 2 + 1
	if m == a:
		print(a - 1)
	elif m > a:
		print(m - 1)
	else:
		print(m + 1)


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


(n, m) = [int(i) for i in input().split()]
if n == 1:
	ans = 1
elif m - 1 > n - m - 1:
	ans = m - 1
else:
	ans = m + 1
print(ans)


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


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


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


inf = list(map(int, input().split()))
mid = (1 + inf[0]) / 2
ans = 0
if inf[1] < mid:
	ans = inf[1] + 1
else:
	ans = inf[1] - 1
print(max(1, ans))


(n, m) = map(int, input().split())
x = abs(n - m)
y = abs(m - 1)
ans = 0
if x > y:
	ans = m + 1
elif x < y:
	ans = m - 1
elif m != 1:
	ans = m - 1
elif m != n:
	ans = m + 1
else:
	ans = m
print(ans)


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


import sys
import math

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, sys.stdin.readline().strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	(n, m) = scan(int)
	if m - 1 >= n - m:
		print(max(m - 1, 1))
	else:
		print(min(n, m + 1))
main()


import sys
import math
import itertools

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

def in1():
	return int(input())
(n, k) = get_line()
if n == 1 and k == 1:
	print(1)
elif n % 2 != 0:
	t1 = n // 2 + 1
	if t1 == k:
		print(k - 1)
	elif k < t1:
		print(k + 1)
	else:
		print(k - 1)
else:
	t1 = n // 2
	if k == t1:
		print(k + 1)
	elif k > t1:
		print(k - 1)
	else:
		print(k + 1)


(n, m) = str(input()).split()
n = int(n)
m = int(m)
if n == 1:
	print(1)
elif n - m > m - 1:
	print(m + 1)
else:
	print(m - 1)


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


def only_one():
	(numb, mumb) = map(int, input().split())
	if numb == 1:
		print(1)
		return
	if numb % 2 == 0:
		mid_min = int(numb / 2)
		mid_max = mid_min + 1
		if mumb == mid_min or mumb == mid_max:
			print(mid_min if mumb == mid_max else mid_max)
		elif mumb < mid_min:
			print(mumb + 1)
		else:
			print(mumb - 1)
	else:
		mid_min = int(numb / 2 + 1)
		if mumb < mid_min:
			print(mumb + 1)
		else:
			print(mumb - 1)
only_one()


from collections import Counter
import string
import math

def array_int():
	return [int(i) for i in input().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(input())
	if number_of_variables >= 2:
		return map(int, input().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
if 1:
	(n, m) = vary(2)
	if 1:
		if n == 1:
			print(1)
		elif n == 2:
			if m != 2:
				print(2)
			else:
				print(1)
		elif n % 2 != 0:
			if n // 2 + 1 <= m:
				print(m - 1)
			else:
				print(m + 1)
		elif n // 2 >= m:
			print(m + 1)
		else:
			print(m - 1)


a = input().split(' ')
lista = []
for i in a:
	lista.append(int(i))
if lista[0] == 1 and lista[-1] == 1:
	print(1)
elif lista[-1] > lista[0] / 2:
	print(lista[-1] - 1)
elif lista[-1] <= lista[0] / 2:
	print(lista[-1] + 1)


import sys
x = str(input()).split()
n = int(x[0])
m = int(x[1])
if n == 1:
	print(1)
	sys.exit()
if n // 2 < m:
	print(m - 1)
else:
	print(m + 1)


def count_probability(n, m, a):
	return sum((1 for c in range(1, n + 1) if abs(a - c) < abs(m - c)))

def visualize(n, m=None):
	from pprint import pprint
	t = [[count_probability(n, m, a) for a in range(1, n + 1)] for m in range(1, n + 1)]
	if m is None:
		pprint(t)
	else:
		print(t[m - 1])

def main():
	(n, m) = map(int, input().split())
	if n == 1:
		print(1)
	elif m == 1:
		print(2)
	elif m == n:
		print(n - 1)
	else:
		(l, r) = (m - 1, n - m)
		if r > l:
			print(m + 1)
		else:
			print(m - 1)
main()


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


a = input()
a = a.split()
if a[0] == '1':
	print(1)
elif int(a[1]) <= int(a[0]) // 2:
	print(int(a[1]) + 1)
else:
	print(int(a[1]) - 1)


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


c = list(map(int, input().split()))
if c[0] == 1:
	print(1)
elif c[0] < 2 * c[1]:
	print(c[1] - 1)
else:
	print(c[1] + 1)


import sys
(n, m) = map(int, sys.stdin.readline().split())
ans = 0
if n == 1:
	ans = 1
elif m * 2 < n + 1:
	ans = m + 1
else:
	ans = m - 1
print(ans)


def read_list(t):
	return [t(x) for x in input().split()]

def read_line(t):
	return t(input())

def read_lines(t, N):
	return [t(input()) for _ in range(N)]
(N, M) = read_list(int)
(small, large) = (M - 1, N - M)
if N == 1:
	print(1)
elif small >= large:
	print(M - 1)
else:
	print(M + 1)


count1 = 0
count2 = 0
nm = input().split()
n = int(nm[0])
m = int(nm[1])
if n == 1 and m == 1:
	print(1)
elif m - 1 >= n - m:
	print(m - 1)
else:
	print(m + 1)


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


import statistics

def solve(n, m):
	med = 0
	if n == 1 and m == 1:
		a = 1
	elif n % 2 == 0:
		med = (n + 1) / 2
		if m > med:
			a = m - 1
		elif m < med:
			a = m + 1
	elif n % 2 != 0:
		med = n // 2 + 1
		if m < med:
			a = m + 1
		elif m > med:
			a = m - 1
		else:
			a = m - 1
	print(a)
(n, m) = map(int, input().split())
solve(n, m)


c = input().split()
x = int(c[0])
y = int(c[1])
if x == 1 and y == 1:
	print('1')
elif x - y > y - 1:
	print(y + 1)
else:
	print(y - 1)


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


(b, a) = map(int, input().split())
print(max(1, a - 1 if a - 2 >= b - (a + 1) else a + 1))


(N, M) = map(int, input().split())
L = M - 1
D = N - M
if L >= D:
	print(max(1, M - 1))
else:
	print(min(N, M + 1))


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
from bisect import bisect_left
(n, m) = list(map(int, stdin.readline().split()))
if n == 1:
	print(1)
	exit()
if n % 2 == 0:
	if m < n // 2:
		print(m + 1)
	elif m > n // 2:
		print(m - 1)
	else:
		print(m + 1)
else:
	mid = n // 2 + 1
	if m > mid:
		print(m - 1)
	elif m < mid:
		print(m + 1)
	elif mid == 1:
		print(m + 1)
	else:
		print(m - 1)


(n, m) = map(int, input().split())
if m == n and n == 1:
	print(1)
elif n - m > m - 1:
	print(m + 1)
elif n - m < m - 1:
	print(m - 1)
elif n - m == m - 1:
	print(m - 1)


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


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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 value():
	return map(int, input().split())

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


def ip():
	return int(input())

def sip():
	return input()

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst
(n, m) = mip()
if n == 1:
	print(1)
elif m - 1 < n - m:
	print(m + 1)
else:
	print(m - 1)


def simple_game(n, m):
	if n == 1:
		return 1
	k = n - m
	if k >= m:
		return m + 1
	else:
		return m - 1
[n, m] = map(int, input().split())
result = simple_game(n, m)
print(result)


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


import itertools as ittls
from collections import Counter
import re
import math

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
(N, M) = inputarray()
if N == 1:
	print(1)
	quit()
if N - M > M - 1:
	print(M + 1)
else:
	print(M - 1)


import sys
sys.setrecursionlimit(1000000)

def solve():
	(n, m) = rv()
	if n == 1:
		return 1
	toleft = m - 1
	toright = n - m
	if toleft >= toright:
		return m - 1
	return m + 1

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

def rl(n):
	return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
print(solve())


(n, m) = map(int, input().split())
(range1, range2) = (n - m, m - 1)
if n == 1:
	print(1)
else:
	print(m + 1 if range1 > range2 else m - 1)


(a, b) = map(int, input().split())
lft = b - 1
rgt = a - b
if a == 1:
	print(1)
elif lft >= rgt:
	print(b - 1)
else:
	print(b + 1)


(n, m) = map(int, input().split())
x = m - 1
y = n - m
if x > y:
	print(m - 1)
elif y > x:
	print(m + 1)
elif n // 2 + 1 == m and n != m:
	print(n - m)
else:
	print(m)


def bf(n, m, a):
	k = 0
	for c in range(1, n + 1):
		if abs(c - a) < abs(c - m):
			k += 1
	return k

def solve(n, m):
	maxx = 0
	for i in range(1, n + 1):
		maxx = max(maxx, bf(n, m, i))
	for i in range(1, n + 1):
		if bf(n, m, i) == maxx:
			return i

def solve2(a, b):
	if a == 1 and b == 1:
		return 1
	if a == b:
		return a - 1
	if b >= a:
		return max(a - (b - a) + 1, 1)
	k = b - 1
	l = b + 1
	c1 = a - l + 1
	if k >= c1:
		return k
	else:
		return l
(a, b) = list(map(int, input().split(' ')))
print(solve2(a, b))


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


sinput = input()
data = sinput.split()
n = int(data[0])
m = int(data[1])
if n == 1:
	print(1)
elif m <= n / 2:
	print(m + 1)
else:
	print(m - 1)


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


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


(n, m) = map(int, input().split())
if n == 1 and m == 1:
	print(1)
	exit()
if m <= n // 2:
	ans = m + 1
else:
	ans = m - 1
print(ans)


(n, m) = map(int, input().split())
left = m - 1
right = n - m
if left >= right:
	ans = m - 1
else:
	ans = m + 1
if ans <= 0:
	ans = 1
if ans >= n:
	ans = n
print(ans)


def ort(n, m):
	if n - m > m - 1:
		return 1
	else:
		return -1

def fra(a):
	return m + a
(n, m) = map(int, input().split())
if n > 1:
	print(fra(ort(n, m)))
else:
	print('1')


def main():
	(n, m) = [int(t) for t in input().split()]
	if n == 1:
		print(1)
	elif m <= n / 2.0:
		print(m + 1)
	else:
		print(m - 1)

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split(' '))
if n == 1:
	print(1)
	exit()
r = n - m
l = m
print(m - 1 if l > r else m + 1)


(n, m) = list((int(a) for a in input().split()))
if n == 1:
	print(1)
else:
	print(m + 1 if n - m >= m else m - 1)


from sys import stdin
from sys import exit
live = True
if not live:
	stdin = open('data.in', 'r')
(n, m) = list(map(int, stdin.readline().strip().split()))
if n == 1 and m == 1:
	print(1)
	exit(0)
if m - 1 >= n - m:
	print(m - 1)
else:
	print(m + 1)
if not live:
	stdin.close()


(n, m) = map(int, input().split())
if abs(m - n) > abs(m - 1):
	print(m + 1)
elif abs(m - n) < abs(m - 1):
	print(m - 1)
elif n == 1:
	print(m)
else:
	print(m - 1)


(n, m) = [int(i) for i in input().split(' ')]
a = m
if not n == 1:
	if m - 1 < n - m:
		a = m + 1
	else:
		a = m - 1
print(a)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
for t in range(0, test):
	(n, m) = list(map(int, input().strip().split()))
	mplus1 = n - m
	mminus1 = m - 1
	if mplus1 > mminus1:
		print(m + 1)
	else:
		print(max(1, m - 1))
	ans = solve()


from math import ceil
params = input()
params_toks = params.split(' ')
range_max = int(params_toks[0])
a = int(params_toks[1])
if range_max == 1:
	guess = 1
else:
	distance_left = abs(a - 1)
	distance_right = abs(a - range_max)
	if distance_right == 0:
		guess = a - 1
	elif distance_left == 0:
		guess = a + 1
	elif distance_left < distance_right:
		guess = a + 1
	else:
		guess = a - 1
print(int(guess))


def simple_game(a, b):
	if abs(b - 1) > abs(a - b):
		return b - 1
	elif abs(b - 1) == abs(a - b):
		if a == 1:
			return 1
		else:
			return b - 1
	return b + 1
(n, m) = [int(i) for i in input().split()]
print(simple_game(n, m))


(n, m) = map(int, input().split())
ans = 0
left = m - 1
right = n - m
if m != 1 and m != n:
	if right > left:
		ans = m + 1
	elif left > right:
		ans = m - 1
	elif left == right:
		ans = m - 1
elif m == n != 1:
	ans = n - 1
elif m == 1 and n != 1:
	ans = m + 1
elif m == n == 1:
	ans = 1
print(ans)


(n, m) = (int(t) for t in input().split())
mid = (1 + n) / 2
if m == mid:
	print(m - 1 if n != 1 else 1)
elif m < mid:
	print(m + 1)
else:
	print(m - 1)


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


def main():
	(n, m) = list(map(int, input().split()))
	if n == 1:
		print(1)
	else:
		(left, right) = (max(0, m - 1), max(0, n - m))
		if left >= right:
			print(m - 1)
		else:
			print(m + 1)

def __starting_point():
	main()
__starting_point()


def main():
	(n, x) = map(int, input().split())
	if n == 1:
		print(1)
		return
	print(x + 1 if x - 1 < n - x else x - 1)
main()


(n, m) = [int(x) for x in input().split()]
if m == 1 and n == 1:
	print(1)
elif m - 1 >= n - m:
	print(m - 1)
else:
	print(m + 1)


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(n, m):
	if n == 1:
		return 1
	if m <= n // 2:
		return m + 1
	else:
		return m - 1

def print_stderr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def main():
	[n, m] = [int(i) for i in input().strip().split()]
	result = solve(n, m)
	print(result)

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split(' '))
p = m - 1
P = n - m
if P > p:
	r = m + 1
else:
	r = m - 1
if r == 0:
	r = 1
print(r)


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


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


import os, io
from sys import stdout
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def isValid(i, j, n, m):
	return i >= 0 and i < n and (j >= 0) and (j < m)

def print_grid(grid):
	for line in grid:
		print(' '.join(map(str, line)))

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def ceil(n, d):
	if n % d == 0:
		return n // d
	else:
		return n // d + 1
(n, a) = list(map(int, input().split()))
if n == 1:
	print(1)
	exit()
if n == 2:
	if a == 1:
		print(2)
		exit()
	print(1)
	exit()
if n - (a + 1) + 1 > a - 1:
	print(a + 1)
else:
	print(a - 1)


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


(n, m) = [int(x) for x in input().split()]
if n > 1:
	if m - 1 >= n - m:
		ans = m - 1
	else:
		ans = m + 1
if n == 1:
	ans = 1
print(ans)


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


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


from math import ceil, floor
(n, m) = map(int, input().split())
r = floor(n / 2)
if n == m == 1:
	print(1)
elif m <= r:
	print(m + 1)
else:
	print(m - 1)


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


s = input().split()
n = int(s[0])
m = int(s[1])
if m >= (n + 1) / 2:
	print(max(m - 1, 1))
elif m < (n + 1) / 2:
	print(min(m + 1, n))


from math import ceil
(n, m) = map(int, input().split())
if int(n / 2) < m:
	ans = m - 1
else:
	ans = m + 1
if ans < 1:
	ans = 1
elif ans > n:
	ans = n
print(ans)


import sys
import math
input = sys.stdin.readline
(n, m) = list(map(int, input().strip().split(' ')))
if n == m == 1:
	print('1')
elif m - 1 < n - m:
	print(m + 1)
else:
	print(m - 1)


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


(n, mi) = input().split(' ')
n = int(n)
mi = int(mi)
if n > 1:
	if mi == 1:
		print(2)
	elif n - mi + 1 > mi:
		print(mi + 1)
	else:
		print(mi - 1)
else:
	print(1)


lst = [eval(i) for i in input().split()]
if lst[0] - lst[1] > lst[1] - 1:
	print(str(lst[1] + 1) + '\n')
elif lst[0] == 1:
	print('1\n')
else:
	print(str(lst[1] - 1) + '\n')


import math
import sys
x = list(map(int, input().split()))
n = x[0]
m = x[1]
if m > int(n / 2):
	a = m - 1
else:
	a = m + 1
if n == 1 and m == 1:
	a = 1
print(a)


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


(n, m) = list(map(int, input().split()))
if n - m > m - 1:
	print(min(m + 1, n))
else:
	print(max(m - 1, 1))
import time, sys
sys.stderr.write('{0:.3f} ms\n'.format(time.clock() * 1000))


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def iseven(n):
	return n % 2 == 0

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime
(n, m) = sp()
ans = ceil(n / 2)
if n == m == 1:
	exit(print(1))
if m == ans and (not iseven(n)):
	print(m - 1)
if m == ans and iseven(n):
	print(m + 1)
else:
	if m > ans:
		print(m - 1)
	if m < ans:
		print(m + 1)
endtime = time.time()


param = input().split(' ')
n = int(param[0])
m = int(param[1])
if m - 1 >= n - m:
	if m - 1 == 0:
		print(m)
	else:
		print(str(m - 1))
else:
	print(str(m + 1))


(sizeOfRange, otherpick) = map(int, input().split())
if sizeOfRange == 1 and otherpick == 1:
	print(sizeOfRange)
elif sizeOfRange / 2 < otherpick:
	print(otherpick - 1)
else:
	print(otherpick + 1)


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


(N, M) = map(int, input().split())
if N == 1:
	print(1)
	exit()
if N - M == M - 1:
	print(M - 1)
elif N - M > M - 1:
	print(M + 1)
else:
	print(M - 1)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def main():
	(n, m) = vars()
	if m <= n // 2:
		print(m + 1)
	else:
		if m - 1 == 0:
			m = n + 1
		print(m - 1)
t = 1
for _ in range(t):
	main()


(a, b) = map(int, input().split())
x = a - b
y = b - 1
if a == 1 and b == 1:
	print(a)
elif x > y:
	print(b + 1)
else:
	print(b - 1)


def main():
	(n, m) = [int(x) for x in input().split()]
	left = m - 1
	right = n - m
	if n == 1 and m == 1:
		print('1')
	elif left == right:
		print(left)
	elif left > right:
		print(left)
	else:
		print(m + 1)
main()


(n, m) = map(int, input().split())
left = m - 1
right = n - m
if left >= right:
	if m - 1 >= 1:
		print(m - 1)
	else:
		print(m)
elif m + 1 <= n:
	print(m + 1)
else:
	print(m)


data = input().split(' ')
(n, m) = (int(data[0]), int(data[1]))
right_num_count = n - m
left_num_count = m - 1
if n == 1:
	print(1)
elif right_num_count > left_num_count:
	print(m + 1)
else:
	print(m - 1)


import sys
(n, m) = map(int, sys.stdin.readline().split())
if m <= n // 2:
	print(max(1, m + 1))
else:
	print(max(1, m - 1))


import sys
fin = sys.stdin
[n, m] = [int(x) for x in fin.readline().split()]
left = m - 1
right = n - m
if left >= right:
	print(max(m - 1, 1))
else:
	print(min(m + 1, n))


l = list(map(int, input().split()))
if l[0] == 1 and l[1] == 1:
	print('1')
elif 2 * l[1] > l[0]:
	print(l[1] - 1)
else:
	print(l[1] + 1)


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


def find_best(number, misha):
	right = number - misha
	if right > misha - 1:
		print(misha + 1)
	else:
		print(misha - 1)
(number, misha) = input().split(' ')
if int(number) == 1:
	print(1)
else:
	find_best(int(number), int(misha))


from sys import stdin
import math
(n, m) = map(int, stdin.readline().split())
k = n - m
if n == 1:
	print(1)
elif m <= k:
	print(m + 1)
else:
	print(m - 1)


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


line1 = [int(x) for x in input().split()]
if line1[0] == 1:
	print(1)
elif line1[1] - 1 >= line1[0] - line1[1]:
	print(line1[1] - 1)
else:
	print(line1[1] + 1)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = map(int, input().split())
if n != 1 or m != 1:
	print(m + 1 if m <= n // 2 else m - 1)
else:
	print(m)


stin = input().split(' ')
n = int(stin[0])
m = int(stin[1])
if n == 1:
	print(1)
elif n - m > m - 1:
	print(m + 1)
else:
	print(m - 1)


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


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


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	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
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, m) = int_array()
if n == 1:
	print(1)
	exit()
if m > n - m:
	print(m - 1)
else:
	print(m + 1)


def main():
	(n, m) = [int(i) for i in input().split()]
	if n == m == 1:
		print(1)
		return 0
	if m > n - m:
		print(m - 1)
	else:
		print(m + 1)
main()


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 fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(1):
	(n, m) = map(int, input().split())
	if n == 1:
		print(1)
	elif m <= n // 2:
		print(m + 1)
	else:
		print(m - 1)


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


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


(n, m) = [int(i) for i in input().split()]
if n % 2 != 0 and n // 2 + 1 == m:
	print(max(1, m - 1))
elif m > n // 2:
	print(m - 1)
else:
	print(m + 1)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

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

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		(n, m) = invr()
		if n == 1:
			print(n)
		elif m - 1 >= n - m:
			print(m - 1)
		else:
			print(m + 1)
	except Exception as e:
		print(e)
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()


import collections

def f():
	(n, m) = [int(c) for c in input().split()]
	if m > n // 2:
		return max(1, m - 1)
	return min(n, m + 1)
print(f())


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

def solve():
	if n == 1:
		return 1
	a1 = m - 1
	a2 = m + 1
	if a1 < 1:
		return a2
	if a2 > n:
		return a1
	b1 = a1
	b2 = n - a2 + 1
	return a1 if b1 >= b2 else a2
print(solve())


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


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


from math import floor
[n, m] = list(map(int, input().split()))
s = floor(n / 2)
if m > s:
	a = max(m - 1, 1)
else:
	a = min(m + 1, n)
print(a)


datos = str(input())
datos = datos.partition(' ')
rango = int(datos[0])
Misha = int(datos[2])
Borde = rango - Misha
Andrew = rango - (Borde + 1)
while Borde >= Misha:
	Andrew = Misha + 1
	break
while Borde < Misha:
	Andrew = Misha - 1
	break
if Andrew == 1 and Misha != 2:
	Andrew = 2
elif Andrew == 0:
	Andrew = 1
print(Andrew)


q = input().split()
w = int(q[0])
e = int(q[1])
if e - 1 > w - e:
	print(e - 1)
elif e - 1 < w - e:
	print(e + 1)
elif e - 1 == 0:
	print(e)
else:
	print(e - 1)


a = list(input().split())
n = int(a[0])
m = int(a[1])
if n % 2 == 0:
	if m <= n / 2:
		print(int(m + 1))
	else:
		print(int(m - 1))
elif m <= n // 2:
	print(int(m + 1))
elif m != 1:
	print(int(m - 1))
else:
	print(1)


(n, m) = list(map(int, input().split()))
positive = n - m
negative = m - 1
if n == 1 and m == 1:
	print(m)
elif positive > negative:
	print(m + 1)
elif negative >= positive:
	print(m - 1)


def solve(n, m):
	if n == 1:
		return 1
	if n % 2 == 1:
		if m >= (n + 1) // 2:
			return m - 1
		return m + 1
	elif m <= n // 2:
		return m + 1
	return m - 1

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


def single_game(n, m):
	if m == n and m == 1:
		return m
	elif m <= n / 2:
		return m + 1
	else:
		return m - 1
array = list(map(int, input().split()))
n = array[0]
m = array[1]
print(single_game(n, m))


(n, m) = (int(x) for x in input().split())
if n == 1:
	print(1)
elif m - 1 >= n - m:
	print(max(1, m - 1))
else:
	print(min(m + 1, n))


(n, m) = input().split()
n = int(n)
m = int(m)
if n == m and m == 1:
	print(1)
	exit(0)
if n - m + 1 > m:
	print(m + 1)
else:
	print(m - 1)


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


import sys
inp = sys.stdin.readline().split(' ')
n = int(inp[0])
m = int(inp[1])
ans = 1
l = m - 1
g = n - m
if g <= l:
	ans = l
else:
	ans = l + 2
if ans == 0:
	ans = 1
print(ans)


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


(n, m) = map(int, input().split())
p = [m + int(m < n), m - int(m > 1)]
print(p[n - m <= m - 1])


(n, m) = map(int, input().split())
t1 = n - m
t2 = n - t1 - 1
if t1 > t2 and m + 1 <= n:
	print(m + 1)
elif t1 <= t2 and m - 1 >= 1:
	print(m - 1)
elif n == m:
	print(n)


(n, m) = [int(x) for x in input().split(' ')]
if m > n / 2:
	o = m - 1
else:
	o = m + 1
print(min(max(o, 1), 1000000000))


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


(n, m) = map(int, input().split())
if m == 1 and n == 1:
	print('1')
else:
	print(str(m - 1) if m - 1 >= n - m else str(m + 1))


(n, m) = map(int, input().split())
c1 = (2 * m - 1) // 2
c2 = (2 * (n - m) + 1) // 2
if c1 >= c2:
	if m - 1 > 0:
		print(m - 1)
	elif m + 1 <= n:
		print(m + 1)
	else:
		print(m)
elif m + 1 <= n:
	print(m + 1)
elif m - 1 > 0:
	print(m - 1)
else:
	print(m)


import sys
import string
from heapq import *
from bisect import *
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
if k <= n // 2:
	print(k + 1)
else:
	print(max(1, k - 1))


ip = input()
l = ip.split()
n = int(l[0])
m = int(l[1])
if m - 1 > n - m:
	print(m - 1)
elif m - 1 < n - m:
	print(m + 1)
elif m - 1:
	print(m - 1)
else:
	print(m)


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


string = input()
numbers = string.split(' ')
a = int(numbers[0])
b = int(numbers[1])
if a == 1:
	print(a)
elif a < b * 2:
	print(b - 1)
else:
	print(b + 1)


(n, m) = map(int, input().split())
fr = m - 1
sr = n - m
ans = 0
if fr < sr:
	ans = m + 1
else:
	ans = m - 1
if n == 1:
	ans = 1
print(ans)


import sys
(n, m) = map(int, input().split())
var1 = n - m
if n == m == 1:
	print(1)
	exit()
var2 = m
if var2 > var1:
	print(m - 1)
elif var1 >= var2:
	print(m + 1)


def game(n, m):
	if n == 1:
		return 1
	if m - 1 >= n - m:
		return m - 1
	else:
		return m + 1
(n, m) = [int(i) for i in input().split()]
print(game(n, m))


import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction

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

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def main():
	(n, m) = mi(line())
	(left, right) = (m - 1, n - m)
	if m - 1 >= 1 and left >= right:
		print(m - 1)
	elif m + 1 <= n and left < right:
		print(m + 1)
	else:
		print(m)
main()


import math
strs = input()
strs = strs.split(' ')
n = int(strs[0])
a = int(strs[1])
winner = 0
aver = (n + 1) / 2
if a >= aver and a - 1 > 0:
	print(a - 1)
elif a + 1 <= n:
	print(a + 1)
else:
	print(n)


y = [int(x) for x in input().split()]
n = y[0]
m = y[1]
a = 0
if m == 1 and n == 1:
	a = 1
elif m == 1:
	a = m + 1
elif m == n / 2:
	a = m + 1
elif n - m > m - 1:
	a = m + 1
else:
	a = m - 1
print(a)


import math
import sys
import collections
import bisect
import string
import time

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, m) = get_ints()
	if n == 1:
		print(1)
	elif m <= n // 2:
		print(m + 1)
	else:
		print(m - 1)


(n, m) = list(map(int, input().split()))
if n == 1:
	print(1)
	exit()
if n % 2 == 1:
	mid = (n + 1) // 2
	if m < mid:
		print(m + 1)
	else:
		print(m - 1)
else:
	mid1 = (n + 1) // 2
	mid2 = (n + 2) // 2
	if m == mid1:
		print(mid2)
	elif m == mid2:
		print(mid1)
	elif m > mid2:
		print(m - 1)
	else:
		print(m + 1)


(n, m) = map(int, input().split())
ka = m - 1
ko = n - m
if ko > ka:
	print(m + 1)
elif ka > ko:
	print(m - 1)
elif ka == 0:
	print(m)
else:
	print(m - 1)


import sys

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

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

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
if m == 1:
	if n == 1:
		print(1)
	else:
		print(m + 1)
elif m == n:
	print(m - 1)
elif m - 1 >= n - m:
	print(m - 1)
else:
	print(m + 1)


(m, c) = [int(x) for x in input().split()]
print((c - 1 if c - 1 >= m - c else c + 1) if m != 1 else 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, 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 [int(x) for x in sys.stdin.readline().split()]

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 main():
	(n, m) = LI()
	if n == 1:
		return 1
	if (n + 1) / 2 <= m:
		return m - 1
	return m + 1
print(main())


x = [int(y) for y in input().split()]
if x[1] == 1:
	if x[0] == 1:
		print(1)
	else:
		print(2)
elif x[0] - x[1] >= x[1]:
	print(x[1] + 1)
else:
	print(x[1] - 1)


(n, m) = input().split()
n = int(n)
m = int(m)
if m - 1 >= n - m and m != 1:
	print(m - 1)
elif n == 1:
	print(1)
else:
	print(m + 1)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
left_range = m - 1
right_range = n - m
if left_range == 0 and right_range == 0:
	print(1)
elif left_range == 0:
	print(m + 1)
elif right_range == 0:
	print(m - 1)
elif left_range < right_range:
	print(m + 1)
else:
	print(m - 1)


def R():
	return map(int, input().split())
(n, m) = R()
if n == 1:
	print(1)
	exit
elif n - m > m - 1:
	print(m + 1)
else:
	print(m - 1)


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


(n, m) = input().split()
n = int(n)
m = int(m)
p = n - m
if n == 1:
	print(1)
elif p >= m:
	print(m + 1)
else:
	print(m - 1)


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


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
cu = lambda x: max(0, x - 1)
cd = lambda x: min(r - 1, x + 1)
cl = lambda x: max(0, x - 1)
cr = lambda x: min(c - 1, x + 1)
(n, m) = R()
print(1 if n == 1 else m + 1 if n - m > m - 1 else m - 1)


import sys
sys.setrecursionlimit(10 ** 7)
from collections import deque
import math
(n, m) = [int(x) for x in input().split()]
(auxl, auxr) = (m - 1, n - m)
if auxl == 0 and auxr == 0:
	print(m)
elif auxl >= auxr:
	print(m - 1)
else:
	print(m + 1)


import sys
import math
import bisect

def main():
	(n, m) = map(int, input().split())
	max_val = 0
	sol = m
	if m < n:
		val = n - m
		if max_val < val or (max_val == val and sol > m + 1):
			max_val = val
			sol = m + 1
	if m > 1:
		val = m - 1
		if max_val < val or (max_val == val and sol > m - 1):
			max_val = val
			sol = m - 1
	print(sol)
main()


import sys
import math
import itertools
import functools
import collections

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

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

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

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

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
(n, m) = mi()
if m == 1 and n == 1:
	print(1)
elif n % 2 and (n + 1) // 2 == m or 2 * m > n:
	print(m - 1)
else:
	print(m + 1)


strin = str(input()).split(sep=' ')
n = int(strin[0])
m = int(strin[1])
s = n / 2
if n != 1:
	if n % 2 == 0:
		if m > s:
			print(m - 1)
		if m < s:
			print(m + 1)
		if m == s:
			print(m + 1)
	else:
		if m > s:
			print(m - 1)
		if m < s:
			print(m + 1)
else:
	print('1')


__author__ = 'artyom'

def main():
	(n, m) = read(3)
	if n == 1:
		return 1
	return m - 1 if m > n // 2 else m + 1

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


from sys import stdin
(n, m) = map(int, stdin.readline().strip().split())
if n == 1:
	print(1)
elif abs(m - 1) < abs(n - m):
	print(m + 1)
else:
	print(m - 1)


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
if n == 1:
	print(1)
elif n % 2:
	p = n // 2 + 1
	if m > p:
		print(m - 1)
	elif m < p:
		print(m + 1)
	else:
		print(p - 1)
else:
	p = n // 2
	q = p + 1
	if m == p:
		print(q)
	elif m == q:
		print(p)
	elif m > q:
		print(m - 1)
	elif m < p:
		print(m + 1)


import os
import sys
from io import BytesIO, IOBase

def solution(n, m):
	if n & 1 == 1:
		mid = n // 2 + 1
		if m > mid:
			write(m - 1)
		elif m < mid:
			write(m + 1)
		else:
			write(mid - 1 if n > 1 else 1)
	else:
		(mid1, mid2) = (n // 2, n // 2 + 1)
		if m < mid1:
			write(m + 1)
		elif m > mid2:
			write(m - 1)
		else:
			write(m + 1 if m == mid1 else m - 1)

def main():
	(n, m) = r_array()
	solution(n, m)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())
main()


import time
(n, m) = (int(i) for i in input().split())
start = time.time()
if n == 1:
	ans = 1
elif m - 1 >= n - m:
	ans = m - 1
else:
	ans = m + 1
print(ans)
finish = time.time()