Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. 

What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?


-----Input-----

The single line contains two space separated integers n, m (0 < n ≤ 10000, 1 < m ≤ 10).


-----Output-----

Print a single integer — the minimal number of moves being a multiple of m. If there is no way he can climb satisfying condition print  - 1 instead.


-----Examples-----
Input
10 2

Output
6

Input
3 5

Output
-1



-----Note-----

For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.

For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
(n, m) = input().split(' ')
n = int(n)
m = int(m)

def how_many_moves(n, m):
	for i in range(n):
		if m * 2 * i >= n:
			return m * i
total_moves = how_many_moves(n, m)
if n >= m:
	print(total_moves)
else:
	print(-1)


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


(n, m) = map(int, input().split())
c = (n + 1) // 2
while c % m:
	c += 1
print([c, -1][n < m])


(a, b) = [int(x) for x in input().split()]
if b > a:
	print('-1')
elif b == a:
	print(b)
elif b == 1:
	print(a // 2 + 1)
else:
	counter = b
	if 2 * counter < a:
		while 2 * counter < a:
			counter += b
	print(counter)


(a, b) = map(int, input().split())
if a < b:
	print(-1)
else:
	v = a // 2
	u = a % 2
	t = v + u
	if t % b == 0:
		print(t)
	else:
		while 1:
			if t % b == 0:
				break
			else:
				t = t + 1
		print(t)


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


from math import ceil
(n, m) = [int(x) for x in input().split()]
if n < m:
	print(-1)
else:
	print(ceil(n / (2 * m)) * m)


num = input().split()
num = list(map(int, num))
n = num[0]
m = num[1]
lis = []
div = n / 2
for x in range(1, 10000):
	lis.append(x * m)
if m <= n:
	for i in lis:
		if i - div >= 0:
			print(i)
			break
else:
	print('-1')


from sys import stdin
(n, m) = map(int, stdin.readline().rstrip().split())
(s2, s1) = (n // 2, n % 2)
for x in range(s2 + s1, s2 * 2 + s1 + 1):
	if not x % m:
		print(x)
		break
else:
	print(-1)


(n, m) = map(int, input().split())
count = 0
mylist = []
if n % 2 == 0:
	for i in range(int(n / 2)):
		mylist.append(2)
	while len(mylist) % m != 0:
		if 2 in mylist:
			mylist.remove(2)
			mylist.append(1)
			mylist.append(1)
		else:
			break
	if len(mylist) >= n / 2 and len(mylist) <= n and (len(mylist) % m == 0):
		print(len(mylist))
	else:
		print('-1')
else:
	for i in range(int((n - 1) / 2)):
		mylist.append(2)
	mylist.append(1)
	while len(mylist) % m != 0:
		if 2 in mylist:
			mylist.remove(2)
			mylist.append(1)
			mylist.append(1)
		else:
			break
	if len(mylist) >= (n + 1) / 2 and len(mylist) <= n and (len(mylist) % m == 0):
		print(len(mylist))
	else:
		print('-1')


(x, y) = map(int, input().split())
d = ((x + 1) // 2 + y - 1) // y * y
print(d if d <= x else '-1')


(n, k) = map(int, input().split())
if n < k:
	print(-1)
else:
	if n % 2 == 0:
		res = n // 2
	else:
		res = n // 2 + 1
	if res % k == 0:
		print(res)
	else:
		val = k - res % k
		print(res + val)


(n, m) = [int(i) for i in input().split()]
for i in reversed(range(0, n // 2 + 1)):
	s = i + n - 2 * i
	if s % m == 0:
		print(s)
		break
else:
	print(-1)


(n, m) = map(int, input().split())
i = 0
t = n
while n - 2 * i >= 0:
	if (n - i) % m == 0 and n - i < t:
		t = n - i
	i += 1
if t % m == 0:
	print(t)
else:
	print(-1)


(n, m) = [int(x) for x in input().split()]
i = 1
val = m
while True:
	if m > n:
		print(-1)
		break
	elif 2 * val < n:
		i += 1
		val = m * i
	else:
		print(val)
		break


import math
(n, m) = map(int, input().split())
move = list(range(math.ceil(n / 2), n + 1))
k = m
while k <= n:
	if k in move:
		print(k)
		break
	else:
		k = k + m
if k > n:
	print(-1)


import math
(n, m) = [int(x) for x in input().split(' ')]
if n == 0:
	ans = 0
elif m > n:
	ans = -1
else:
	ans = m * math.ceil(math.ceil(n / 2) / m)
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
if n % 2 == 0:
	k = int(n / 2)
	for i in range(k, n + 1):
		if i == n:
			if i % m == 0:
				print(i)
				exit()
			else:
				print(-1)
				exit()
		if i % m == 0:
			print(i)
			exit()
else:
	k = int(n / 2) + 1
	for i in range(k, n + 1):
		if i == n:
			if i % m == 0:
				print(i)
				exit()
			else:
				print(-1)
				exit()
		if i % m == 0:
			print(i)
			exit()


(n, m) = [int(x) for x in input().split()]
if n < m:
	print(-1)
else:
	k = n // 2
	p = n - 2 * k
	while (k + p) % m != 0:
		k -= 1
		p = n - 2 * k
	print(k + p)


(n, m) = [int(x) for x in input().split()]
if m > n:
	print(-1)
else:
	moves = m
	step = 2 * m
	while step < n:
		moves += m
		step = 2 * moves
	print(moves)


import math
a = [int(x) for x in input().split()]
n = a[0]
m = a[1]
if math.ceil(math.ceil(n / 2) / m) > math.floor(n / m):
	print(-1)
else:
	print(m * math.ceil(math.ceil(n / 2) / m))


from math import floor
(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	(sm, c) = (0, 0)
	while sm < n:
		sm += 2
		c += 1
	while c % m != 0:
		c += 1
	if c > n:
		print(-1)
	else:
		print(c)


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


(n, m) = map(int, input().split())
l = []
a = []
if m > n:
	print(-1)
if n >= m:
	while n >= 0:
		for j in range(0, m):
			a.append(n - 2)
			n = n - 2
		l.append(a)
		a = []
		if n <= 0:
			print(len(l) * m)
			break


(n, b) = map(int, input().split())
lis = [-1]
for i in range((n + 1) // 2, n + 1):
	if i % b == 0:
		lis.append(i)
		break
print(max(lis))


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


X = list(map(int, input().split()))
if X[0] >= X[1]:
	Divide = X[0] // 2 + X[0] % 2
	print(Divide + (X[1] - Divide % X[1] if Divide % X[1] != 0 else 0))
	exit()
print(-1)


import math
import sys
(n, m) = map(int, input().split())
a = math.ceil(n / 2.0)
for i in range(a, min(n + 1, a + m)):
	if i % m == 0:
		print(i)
		sys.exit()
print(-1)


(n, v) = list(map(int, input().strip().split()))
if n % 2 == 0:
	arr = [2] * (n // 2)
else:
	arr = [2] * (n // 2)
	arr += [1]

def f(array, m):
	if len(array) % m != 0:
		array.remove(2)
		array.append(1)
		array.append(1)
		return f(array, m)
	else:
		return len(array)
if v > n:
	print(-1)
else:
	print(f(arr, v))


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	y = n // 2
	if n % 2 == 1:
		y += 1
	for i in range(m):
		if y % m == 0:
			print(y)
			break
		else:
			y += 1


(n, m) = map(int, input().split())
if m > n:
	print(-1)
	exit()
elif m == n:
	print(m)
	exit()
b = n // 2
c = n % 2
d = b + c
if d % m == 0:
	print(d)
else:
	e = d % m
	if e <= b:
		print(d + (m - e))
	else:
		print(-1)


(n, m) = map(int, input().split())
moves = []
for i in range(n // 2):
	moves.append(2)
n -= 2 * (n // 2)
for i in range(n // 1):
	moves.append(1)
while len(moves) % m != 0:
	if 2 in moves:
		moves.remove(2)
		moves.append(1)
		moves.append(1)
	else:
		break
if len(moves) % m == 0:
	print(len(moves))
else:
	print(-1)


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


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


from math import ceil
from typing import List

def parse_input() -> List[int]:
	return [int(x) for x in input().split()]

def solve(n: int, m: int) -> int:
	if m > n:
		return -1
	k = ceil(n / 2)
	if m >= k and m <= n:
		return m
	if k % m == 0:
		return k
	return k + m - k % m
(n, m) = parse_input()
print(solve(n, m))


(n, m) = map(int, input().split())
a = False
for i in range((n - 1) // 2 + 1, n + 1):
	if i % m == 0:
		print(i)
		a = True
		break
if a == False:
	print(-1)


(n, m) = map(int, input().split())
t = m
if n % 2 == 0:
	k = n / 2
	while t < k:
		t = t + m
	if t <= n:
		print(t)
	else:
		print('-1')
else:
	k = (n + 1) / 2
	while t < k:
		t = t + m
	if t <= n:
		print(t)
	else:
		print('-1')


def move(n, m):
	i = m
	while i <= n:
		mini = i * 1
		maxi = i * 2
		if n <= maxi and n >= mini:
			return i
		i += m
	return -1
(n, m) = list(map(int, input().split()))
print(move(n, m))


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


import math
(n, m) = map(int, input().split())
minimum = math.ceil(n / 2)
i = minimum - 1
while True:
	i += 1
	if i % m == 0:
		print(i)
		quit()
	if i == n:
		print(-1)
		quit()


read = lambda : list(map(int, input().split()))
(n, m) = read()
i = 0
MIN = 100000
while n >= 0:
	if (i + n) % m == 0:
		MIN = min(MIN, i + n)
	n -= 2
	i += 1
print(-1 if MIN == 100000 else MIN)


inp = input().split()
n = int(inp[0])
m = int(inp[1])
flag = 0
for i in range((n + 1) // 2, n + 1):
	if i % m == 0:
		flag = 1
		print(i)
		break
if flag == 0:
	print('-1')


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


user = list(input().split())
m = int(user[0])
n = int(user[1])
min = m / 2
if type(min) == float:
	min = int(min + 0.5)
else:
	min = min + 0
c = 0
if m > n:
	for i in range(min, m):
		if i % n == 0:
			c = 1
			a = i
			break
if m == n:
	print(m)
elif c == 1:
	print(a)
else:
	print(-1)


(n, m) = map(int, input().split())
pre = 0
flag = 0
if n < m:
	print(-1)
elif n == m:
	print(n)
else:
	length = n // (m * 2) * m
	pre = length * 2
	if pre != n:
		li = list('2' * m)
		l = [int(x) for x in li]
		for j in range(m):
			if pre + sum(l) != n:
				l[j] -= 1
			elif pre + sum(l) == n:
				break
		length += len(l) - l.count(0)
	if length % m == 0:
		print(length)
	else:
		print(-1)


(n, m) = map(int, input().split())
ans = 100000
if m > n:
	print(-1)
elif n == m:
	print(n)
else:
	for a in range(1, 10000):
		y = n - a * m
		x = a * m - y
		if y < 0 or x < 0:
			continue
		ans = min(ans, x + y)
	print(ans)


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	x = n // 2
	y = n % 2
	if y == 0 and x % m == 0:
		print(x)
	elif y == 1:
		p = (x + 1) % m
		q = (x + 1) // m
		if p == 0:
			print(x + 1)
		else:
			print(m * q + m)
	elif y == 0 and x % m > 0:
		p = x % m
		q = x // m
		print(m * q + m)


def main():
	(n, m) = [int(i) for i in input().split()]
	k = n // 2
	q = n % 2
	while (k + q) % m and k + q <= n:
		k += 1
	if k + q > n:
		print(-1)
	else:
		print(k + q)
main()


__author__ = 'SAUMYA'

def solve():
	(n, m) = map(int, input().split())
	if m > n:
		print(-1)
		return
	elif m == n:
		print(m)
		return
	else:
		num = n // 2
		rem = n % 2
		if (num + rem) % m == 0:
			ans = num + rem
		else:
			factor = (num + rem) // m + 1
			ans = m * factor
		print(ans)
solve()


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
low = (n + 1) // 2
k = (low + m - 1) // m
s = k * m
if s > n:
	print(-1)
else:
	print(s)


x = list(map(int, input().split()))
if x[0] < x[1]:
	print('-1')
else:
	if x[0] % 2 == 0:
		s = x[0] // 2
	else:
		s = x[0] // 2 + 1
	while s % x[1] != 0:
		s += 1
	print(s)


(a, b) = input().split()
a = int(a)
b = int(b)
c = (a + 1) // 2 + b - 1
d = c // b * b
if a >= d:
	print(d)
else:
	print(-1)


(n, m) = map(int, input().split())
a = 0
if n >= m:
	two = int(n / 2)
	if n % 2 == 0:
		one = 0
	else:
		one = 1
	if (two + one) % m == 0:
		a = two + one
	else:
		nn = 0
		for x in range(two):
			nn += 1
			if (two + one + nn) % m == 0:
				a = two + one + nn
				break
print(a) if a > 0 else print(-1)


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


import sys
import os
(n, m) = map(int, sys.stdin.readline().split())
x = 0
p = 0
if n % 2 != 0:
	p = n / 2
	p = p + 1
else:
	p = n / 2
for l in range(int(p), n + 1):
	if l % m == 0:
		x = l
		break
if x > 0:
	print(x)
else:
	print(-1)


(a, b) = map(int, input().split())
hmm = -1
for i in range(a // 2 + a % 2, a + 1):
	if i % b == 0:
		hmm = i
		break
print(hmm)


(n, m) = map(int, input().split())
p = []
if n % 2 == 0:
	r = int(n / 2) - 1
else:
	r = int(n / 2)
for i in range(n, r, -1):
	if i % m == 0:
		p.append(i)
if len(p) != 0:
	print(min(p))
else:
	print(-1)


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


a = input()
tot = len(a)
if a[tot - 1] == '0':
	m = int(10)
	n = int(a[0:tot - 3])
else:
	m = int(a[tot - 1])
	n = int(a[0:tot - 2])
if n % 2 == 0:
	min = n // 2
elif n % 2 == 1:
	min = n // 2 + 1
max = n
small = min // m
big = max // m
if min % m == 0:
	print(min)
elif small == big:
	print(-1)
else:
	print(m * small + m)


import sys
(n, m) = [int(x) for x in input().split()]
k = n // 2
if n % 2 == 1:
	k += 1
for i in range(k, n + 1):
	if i % m == 0:
		print(i)
		sys.exit()
print(-1)


inpList = [int(inpList) for inpList in input().split(' ')]
inpTuple = tuple(inpList)
n = int(inpTuple[0])
m = int(inpTuple[1])
if n >= m:
	if n % 2 == 0:
		moves = n / 2
	else:
		moves = (n + 1) / 2
	if moves % m == 0:
		print(int(moves))
	else:
		cong = moves % m
		diff = m - cong
		print(int(moves + diff))
else:
	print(-1)


(n, m) = input().split()
n = int(n)
m = int(m)
k = 1
while k < n // m + 1:
	if n >= k * m and 2 * k * m >= n:
		print(k * m)
		exit()
	else:
		k = k + 1
print(-1)


(x, y) = list(map(int, input().split()))
aux = (x + 1) // 2
ans = 0
if y > x:
	print(-1)
else:
	while aux % y != 0:
		aux += 1
	print(aux)


from math import ceil
(n, m) = [int(i) for i in input().split()]
if n < m:
	print(-1)
elif n == m:
	print(n)
else:
	l = []
	for i in range(ceil(n / 2), n + 1):
		if i % m == 0:
			l.append(i)
	l.sort()
	print(l[0])


(n, m) = map(int, input().split())
mi = -(-n // 2)
for i in range(mi, n + 1):
	if i % m == 0:
		print(i)
		quit()
print(-1)


(n_val, m_val) = list(map(int, input().split()))
m_prime_max = n_val // 2
x_val = m_prime_max
while x_val >= 0:
	if (n_val - x_val) % m_val == 0:
		print(n_val - x_val)
		exit(0)
	else:
		x_val -= 1
print('-1')


temp = 0
(n, m) = map(int, input().split())
temp = n
if temp % 2 == 0:
	temp /= 2
else:
	temp /= 2
	temp += 0.5
while True:
	if temp % m == 0:
		print(int(temp))
		break
	elif temp % m != 0:
		temp += 1
	if temp > n:
		print(-1)
		break


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


(n, m) = map(int, input().split())
if n < m:
	print(-1)
elif n % 2 == 0:
	l = [2] * int(n / 2)
	while len(l) % m != 0:
		l.remove(2)
		l = l + [1, 1]
	print(len(l))
else:
	l = [2] * int(n / 2)
	l.append(1)
	while len(l) % m != 0:
		l.remove(2)
		l = l + [1, 1]
	print(len(l))


def main():
	nAndM = str(input()).split()
	(n, m) = (int(nAndM[0]), int(nAndM[1]))
	maxX = n // 2
	answers = []
	for x in range(maxX + 1):
		y = n - 2 * x
		if (x + y) % m == 0:
			answers.append(x + y)
		answers.sort()
	if answers:
		print(answers[0])
	else:
		print(-1)

def __starting_point():
	main()
__starting_point()


(n, m) = list(map(int, input().split()))
x = n % 2
if x == 0:
	count = n // 2
	N = count
	bool = True
	while N > -1:
		if n < m:
			print('-1')
			bool = False
			break
		if count % m == 0:
			print(count)
			bool = False
			break
		N -= 1
		count += 1
	if bool == True:
		print('-1')
else:
	count = n // 2 + 1
	N = count
	bool = True
	while N > -1:
		if n < m:
			print('-1')
			bool = False
			break
		if count % m == 0:
			print(count)
			bool = False
			break
		N -= 1
		count += 1
	if bool == True:
		print('-1')


a = list(map(int, input().split()))
a += [(a[0] + 1) // 2]
b = list(filter(lambda x: not x % a[1], range(a[2], a[2] + a[1])))[0]
print(-1 if b > a[0] else b)


from sys import stdin, stdout
DEBUG = True

class Scan:

	def __init__(self):
		self.read = stdin.read
		self.input = stdin.readline

	def integer(self, count=1):
		if count == 1:
			return self._integer()
		return [self._integer() for _ in range(count)]

	def _integer(self):
		sym: str = self.read(1)
		while sym != '-' and (not sym.isdigit()):
			sym = self.read(1)
		(number, sign) = (0, -1) if sym == '-' else (int(sym), 1)
		sym: str = self.read(1)
		while sym.isdigit():
			number = number * 10 + int(sym)
			sym = self.read(1)
		return number * sign

	def array(self, func=int, sep=' '):
		if func == str:
			return input().split(sep)
		return list(map(func, input().split(sep)))

	def string(self, count=1):
		if count == 1:
			return self._string()
		return [self._string() for _ in range(count)]

	def _string(self):
		sym = self.read(1)
		while sym in ('\n', '\r', ' '):
			sym = self.read(1)
		s = str()
		while sym not in ('\n', '\r', ' '):
			s += sym
			sym = self.read(1)
		return s

class Write:
	pass

class Number:

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

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

	def sqrt(n):
		sqrt_n = int(n ** 0.5)
		while sqrt_n * sqrt_n < n:
			sqrt_n += 1
		while sqrt_n * sqrt_n > n:
			sqrt_n -= 1
		return sqrt_n

	def sum_n(n):
		return n * (n + 1) // 2

class Constants:
	EPS = 10 ** (-9)
	INF = 10 ** 18
	MOD = 10 ** 9 + 7

def solution(scan: Scan, write: Write):
	(n, m) = scan.integer(2)
	k = n // 2
	d = n % 2
	if (k + d) % m == 0:
		print(k + d)
	else:
		need = m - (k + d) % m
		if need <= k:
			print(need + k + d)
		else:
			print(-1)

def main():
	queries: int = 1
	(scan, write) = (Scan(), Write())
	for _ in range(queries):
		solution(scan, write)
main()


from math import *

def inp():
	return map(int, input().split())
(n, m) = inp()
(mul, ans, start, end) = (1, -1, ceil(n / 2), n)
while True:
	num = m * mul
	if num >= start and num <= end:
		ans = num
		break
	elif num > end:
		break
	mul += 1
print(ans)


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


def func(n):
	stairs = n[0]
	multiple = n[1]
	if multiple > stairs:
		print(-1)
		return
	if stairs % 2 == 0:
		total = stairs // 2
		while total % multiple != 0:
			total += 1
		if total % multiple != 0:
			print(-1)
		else:
			print(total)
		return
	else:
		total = stairs // 2 + 1
		while total % multiple != 0:
			total += 1
		if total % multiple != 0:
			print(-1)
		else:
			print(total)
		return
n = list(map(int, input().split()))
func(n)


import math
(n, m) = map(int, input().split())
res = -1
for i in range(math.ceil(n / 2), n + 1):
	if i % m == 0:
		res = i
		break
print(res)


import math
(n, m) = map(int, input().split())
a = math.ceil(n / 2)
if n < m:
	print(-1)
else:
	while a % m != 0:
		a = a + 1
	print(a)


(n, m) = map(int, input().split())
ans = -1
for b in range(n // 2, -1, -1):
	a = n - 2 * b
	if (a + b) % m == 0:
		ans = a + b
		break
print(ans)


inp = input().split()
n = int(inp[0])
m = int(inp[1])
i = int(0)
ans = int(2000000000)
while i <= n:
	y = n - 2 * i
	if y < 0:
		i = i + 1
		continue
	if (i + y) % m == 0:
		ans = min(ans, i + y)
	i = i + 1
if ans == 2000000000:
	print(-1)
else:
	print(ans)


import math
(n, m) = map(int, input().split())
upper = n
lower = math.ceil(n / 2)
flag = False
for i in range(lower, upper + 1):
	if i % m == 0:
		print(i)
		flag = True
		break
if flag == False:
	print(-1)


(n, m) = map(int, input().split())
cnt2 = n // 2
cnt1 = n % 2
cnt = cnt2 + cnt1
if cnt % m == 0:
	print(str(cnt))
else:
	dif = m - cnt % m
	if dif > cnt2:
		print('-1')
	else:
		print(str(cnt + dif))


(staircase, m) = map(int, input().split())
minimum_moves = staircase // 2
if staircase < m:
	minimum_moves = -1
elif staircase % 2 != 0:
	minimum_moves = minimum_moves + 1
	if minimum_moves % m != 0:
		minimum_moves = m - minimum_moves % m + minimum_moves
elif staircase % 2 == 0:
	minimum_moves = minimum_moves
	if minimum_moves % m != 0:
		minimum_moves = m - minimum_moves % m + minimum_moves
print(minimum_moves)


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


(n, m) = list(map(int, input().split()))
ans = 0
if n < m:
	print(-1)
	exit()
else:
	if n % 2 == 0:
		temp = n / 2
		if temp % m == 0:
			ans += temp
		else:
			temp2 = m - temp % m
			ans += temp + temp2
	else:
		ans += 1
		temp = n / 2
		if temp % m == 0:
			ans += temp
		else:
			temp2 = m - temp % m
			ans += temp + temp2 - 1
	print(int(ans))


import math
(n, m) = [int(i) for i in input().split()]
if n < m:
	print(-1)
elif n == m:
	print(m)
else:
	k = n // 2 + n % 2
	x = math.ceil(k / m)
	y = x * m
	z = y - k
	if z == k:
		print(k)
	elif z <= n // 2:
		print(y)
	else:
		print(-1)


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


(n, k) = map(int, input().split())
if n % 2 == 0:
	a = n // 2
else:
	a = n // 2 + 1
x = -1
for i in range(a, n + 1):
	if i % k == 0:
		x = i
		break
print(x)


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


q = [int(x) for x in input().split()]
n = q[0]
m = q[1]
count = 0
sum = 0
if n >= m:
	while sum < n:
		sum = sum + 2
		count += 1
	k = count % m
	if k != 0:
		t = m - k
		count = count + t
	print(count)
else:
	print('-1')


import math
from decimal import *
getcontext().prec = 30
(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	print(math.ceil(n / (2 * m)) * m)


(n, m) = map(int, input().split())
inf = n / (2 * m)
sup = n / m
if int(inf) == inf:
	print(int(inf * m))
else:
	x = int(inf) + 1
	if x <= sup:
		print(x * m)
	else:
		print(-1)


(n, m) = map(int, input().split())
import math
low = int(math.ceil(n / 2))
up = n
j = 0
for i in range(low, up + 1):
	if i % m == 0:
		j = i
		break
print(j if j != 0 else -1)


(n, m) = input().split()
n = int(n)
m = int(m)
flag = 0
res = 0
if m > n:
	print(-1)
else:
	while n >= 2 * m:
		res += m
		n -= 2 * m
	if n % (2 * m) != 0:
		res += m
	print(res)


(n, m) = map(int, input().split())
min_moves = (n + 1) // 2
print((min_moves // m + 1) * m) if (min_moves // m + 1) * m <= n and min_moves % m != 0 else print(min_moves) if min_moves <= n and min_moves % m == 0 else print(-1)


import sys
(n, m) = list(map(int, input().split()))
for i in range((n + 1) // 2, n + 1):
	if i % m == 0:
		print(i)
		sys.exit()
print(-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()
	for i in range((n + 1) // 2, n + 1):
		if i % m == 0:
			return i
	return -1
print(main())


from math import ceil
(n, m) = map(int, input().strip().split())
print(ceil(ceil(n / 2) / m) * m if n >= m else -1)


inp = input().split(' ')
l = []
n = int(inp[0])
m = int(inp[1])
if m > n:
	print(-1)
else:
	if n % 2 == 0:
		k = n / 2
	else:
		k = n // 2 + 1
	if k % m == 0:
		print(int(k))
	else:
		while k % m != 0:
			k = k + 1
		print(int(k))


l = input().split()
a = int(l[0])
b = int(l[1])
p = 0
if a == 0:
	print(-1)
elif a % 2 == 0:
	for i in range(a // 2, a + 1):
		if i % b == 0:
			print(i)
			p = 2
			break
		else:
			p = 1
	if p == 1:
		print(-1)
else:
	for i in range(a // 2 + 1, a + 1):
		if i % b == 0:
			print(i)
			p = 2
			break
		else:
			p = 1
	if p == 1:
		print(-1)


(n, m) = map(int, input().split())
if m > n:
	print(-1)
elif m == n:
	print(m)
else:
	if n % 2 == 0:
		minsteps = n / 2
	else:
		minsteps = (n - 1) / 2 + 1
	for x in range(0, int(minsteps) + 1):
		if (minsteps + x) % m == 0:
			flag = True
			break
	if flag:
		print(int(minsteps + x))
	else:
		print(-1)


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


(n, m) = [int(i) for i in input().split()]
if m > n:
	print(-1)
else:
	r = n // 2 + n % 2
	while r % m:
		r += 1
	print(r)


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


import math
A = input().split(' ')
n = int(A[0])
m = int(A[1])
if n < m:
	print(-1)
elif n == m:
	print(m)
else:
	p = int(math.ceil(n / 2))
	if p <= m:
		print(m)
	else:
		pp = p % m
		if pp == 0:
			print(p)
		else:
			print(p + m - pp)


n = input().split()
m = []
for i in n:
	m.append(int(i))
a1 = m[0]
a2 = m[1]
if a1 < a2:
	print('-1')
if a1 == a2:
	print(str(a2))
n = []
if a1 > a2:
	for i in range(5000):
		if a1 % 2 == 0:
			a1 = a1 - int(2)
			if (i + int(1) + a1) % a2 == 0:
				n.append(i + int(1) + a1)
			if a1 <= 0:
				break
		elif a1 % 2 != 0:
			a1 = a1 - int(2)
			if a1 < 0:
				break
			elif (i + int(1) + a1) % a2 == 0:
				n.append(i + int(1) + a1)
	print(str(min(n)))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s1 = n // 2
i = s1
j = n
Min = 100000000
while i >= 0:
	j = n - 2 * i
	if (i + j) % m == 0:
		Min = min(Min, i + j)
	i = i - 1
if Min == 100000000:
	print(-1)
else:
	print(Min)


(n, m) = map(int, input().split())
maximum = n
minimum = 1 + (n - 1) // 2
k = minimum
while k <= maximum and k % m:
	k += 1
if k <= maximum:
	print(k)
else:
	print(-1)


f = list(map(int, input().split(' ')))
n = f[0]
m = f[1]
c = 0
if n % 2 == 0:
	for i in range(n // 2, n + 1):
		if i % m == 0:
			print(i)
			c = i
			break
else:
	for i in range(n // 2 + 1, n + 1):
		if i % m == 0:
			print(i)
			c = i
			break
if c == 0:
	print(-1)


(n, m) = map(int, input().split())
print(['-1', ((n + 1) // 2 + m - 1) // m * m][n >= m])


from math import ceil
(a, b) = map(int, input().split())
if a < b:
	print('-1')
elif a == b:
	print(a)
else:
	x = ceil(a / 2)
	y = ceil(x / b)
	print(y * b)


l1 = [int(x) for x in input().split()]
(n, m) = (l1[0], l1[1])
if m > n:
	print(-1)
else:
	mino = int(n / 2) + n % 2
	maxo = n
	done = 0
	ans = -1
	for x in range(mino, maxo + 1):
		if x % m == 0:
			ans = x
			break
	print(ans)


from math import ceil
(a, b) = map(int, input().split())
if a % 2 == 0:
	(j, k) = (a // 2, a)
else:
	(j, k) = (1 + a // 2, a)
(j, k) = (ceil(j / b), k // b)
print([-1, j * b][j <= k])


ip = input().split(' ')
ip = list(map(int, ip))
n = ip[0]
m = ip[1]
fool = True
ones = 0
if n < m:
	print(-1)
elif n % 2 == 0 and n / 2 % m == 0:
	res = int(n / 2)
	print(res)
else:
	while fool:
		n = n - 1
		ones = ones + 1
		if n % 2 == 0 and (int(n / 2) + ones) % m == 0:
			print(int(n / 2 + ones))
			break


arr = [int(x) for x in input().split()]

def functionSomething(n, m):
	div = int(n / 2)
	result = 0
	while True:
		if int(result % m) == 0 and result > 0:
			print(result)
			break
		elif div == 0 and n % m != 0:
			print(-1)
			break
		elif div == 0 and n % m == 0:
			print(n)
			break
		result = int(div + (n - div * 2))
		div -= 1
functionSomething(arr[0], arr[1])


l = input().split(' ')
n = int(l[0])
m = int(l[1])
y = int(n / 2)
r = n % m
new_y = int(y / m) * m + r
if new_y > y:
	new_y -= m
if new_y >= 0:
	print(n - new_y)
else:
	print(-1)


w = input()
w = w.split()
n = int(w[0])
m = int(w[1])
mind = False
x = int(n / (2 * m))
q = 0
if n >= m:
	moves = n / 2
	while m * x <= n:
		while q <= moves and moves % m == 0:
			if (moves - q) * 2 + q * 1 == n:
				print(int(moves))
				mind = True
				break
			else:
				q = q + 1
		x = x + 1
		moves = m * x
		q = 0
		if mind == True:
			break
	else:
		if mind != True:
			print('-1')
else:
	print('-1')


(n, k) = input().split(' ')
k = int(k)
n = int(n)
x = n - 2 * (n // 2)
y = n // 2
while y >= 0:
	if (x + y) % k == 0:
		print(x + y)
		break
	y -= 1
	x = n - 2 * y
if y == -1:
	print(-1)


import math
(n, m) = [int(x) for x in input().split()]
mn = math.ceil(n / 2)
if m > n:
	print(-1)
else:
	while mn % m != 0:
		mn += 1
	print(mn)


a = list(map(int, input().strip().split()))
n = a[0]
m = a[1]
s = n // 2 + n % 2
while s <= n:
	if s % m == 0:
		break
	else:
		s = s + 1
if s <= n:
	print(s)
else:
	print('-1')


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


from math import ceil
(n, k) = map(int, input().split())
flag = 0
for i in range(ceil(n / 2), n + 1):
	if i % k == 0:
		print(i)
		flag = 1
		break
if flag == 0:
	print(-1)


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


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

def f(n, m):
	for a in range(n // 2, -1, -1):
		b = n - 2 * a
		if (a + b) % m == 0:
			return a + b
	return -1
print(f(n, m))


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


(n, m) = map(int, input().split())
flag = False
for i in range(n + 1):
	if not n - i & 1 and (not (i + (n - i >> 1)) % m):
		flag = True
		print(i + (n - i >> 1))
		break
if not flag:
	print(-1)


a = list(map(int, input().split()))
import math
low = math.ceil(a[0] / 2)
for i in range(low, a[0] + 1):
	if i % a[1] == 0:
		print(i)
		break
else:
	print('-1')


a = [int(s) for s in input().split()]
if a[0] // a[1] == 0:
	k = -1
	print(-1)
else:
	if a[0] % 2 != 0:
		a[0] += 1
	k = a[0] / 2
	while k % a[1] != 0:
		k += 1
if k != -1:
	print(int(k))


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


(n, m) = map(int, input().split())
twos = int(n / 2)
ones = n % 2
totals = twos + ones
q = int(totals / m)
r = totals % m
if r == 0:
	print(m * q)
elif twos >= m - r:
	print(m * (q + 1))
else:
	print(-1)


import math
(n, m) = map(int, input().split())
my_min = n
for k in range(1, math.ceil(n / m)):
	y = n - m * k
	x = m * k - y
	if x >= 0 and y >= 0:
		if x + y < my_min:
			my_min = x + y
if my_min % m != 0:
	print(-1)
else:
	print(my_min)


import math

def problem(x, y):
	return math.ceil(x / y) * y
i = input().split()
n = int(i[0])
m = int(i[1])
ans = problem(math.ceil(n / 2), m)
if ans > n:
	ans = -1
print(ans)


def u():
	(n, m) = map(int, input().split())
	for i in range(1, 100000):
		x = m * i
		sum = 2 * x
		if sum - x <= n and sum >= n:
			print(x)
			return
	print(-1)
	return
u()


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

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


import math
(n, m) = input().split()
m = int(m)
n = int(n)
t = math.ceil(n / 2)
while t <= n:
	if t % m == 0:
		print(int(t))
		break
	t += 1
else:
	print('-1')


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
if m > n:
	print('-1')
elif m == n:
	print(m)
else:
	a = n // 2
	b = n % 2
	while (a + b) % m != 0 and a >= 0:
		a -= 1
		b += 2
	if a >= 0:
		print(a + b)
	else:
		print('-1')


def min_steps(n):
	if n % 2 == 0:
		return n // 2
	else:
		return n // 2 + 1

def steps_needed(minS, m):
	if m >= minS:
		return m
	else:
		while minS % m != 0:
			minS += 1
		return minS
(n, m) = map(int, input().split())
minS = min_steps(n)
s_needed = steps_needed(minS, m)
if s_needed in range(minS, minS + n // 2 + 1):
	print(s_needed)
else:
	print(-1)


def stairs(n, m):
	if n % 2 == 0:
		max = n
		min = n // 2
	else:
		max = n
		min = (n + 1) // 2
	for i in range(min, max + 1):
		if i % m == 0:
			return i
	return -1
(n1, m1) = input().split()
n = int(n1)
m = int(m1)
print(stairs(n, m))


n_m = input('')
n_m_list = list(n_m.split())
(n, m) = [int(n_m_list[0]), int(n_m_list[1])]
lis = []
lis_m = []
for x in range(0, n + 1):
	y = (n - x) / 2
	lis.append(x + y)
for i in lis:
	if i % m == 0:
		lis_m.append(i)
try:
	print(int(min(lis_m)))
except ValueError:
	print(-1)


a = list(map(int, input().split()))
n = a[0]
m = a[1]
flag = 0
for i in range(n // 2, -1, -1):
	if (n - i) % m == 0:
		flag = 1
		print(n - i)
		break
if flag == 0:
	print(-1)


n = [int(x) for x in input().split()]
mi = n[0] // 2 if n[0] // 2 == n[0] / 2 else 1 + n[0] // 2
ma = n[0]
x = -1
for i in range(mi, ma + 1):
	if i % n[1] == 0:
		x = i
		break
print(x)


import math
(n, m) = map(int, input().split())
if m > n:
	print(-1)
elif m == n:
	print(m)
else:
	t = math.ceil(n / 2)
	p = math.ceil(t / m)
	print(m * p)


import math
(n, m) = map(int, input().strip().split(' '))
ans = -1
start = math.ceil(n / 2)
while start <= n:
	if start % m == 0:
		ans = start
		break
	start += 1
print(ans)


import math
(n, m) = map(int, input().split())
if m <= n:
	moves2 = n // 2
	moves1 = 0
	if n % 2 != 0:
		moves1 = 1
	if (moves2 + moves1) % m == 0:
		print(moves2 + moves1)
	else:
		while moves2 > 0:
			moves1 += 2
			moves2 -= 1
			if (moves2 + moves1) % m == 0:
				break
		print(moves2 + moves1)
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
f = -1
for i in range(n // 2 + n % 2, n + 1):
	if i % m == 0:
		f = i
		break
print(f)


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


p = input()
s = [int(i) for i in p.split()]
mins = int(s[0] / 2) + int(s[0] % 2)
found = 0
while mins <= s[0]:
	if mins % s[1] == 0:
		found = 1
		break
	mins += 1
if found == 1:
	print(mins)
else:
	print(-1)


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

def f(n, m):
	(a, b) = (n // 2, n % 2)
	while True:
		if a < 0:
			return -1
		if (a + b) % m == 0:
			return a + b
		a -= 1
		b += 2
print(f(n, m))


z = list(map(int, input().split()))
status = True
count = 0
if z[0] % 2 == 0:
	s = z[0] // 2
else:
	s = z[0] // 2 + 1
while status:
	if (s + count) % z[1] != 0:
		count += 1
	elif s + count <= z[0]:
		print(s + count)
		status = False
	else:
		print(-1)
		status = False


(n, k) = map(int, input().split())
import math as m
if n < k:
	print(-1)
else:
	z = k
	while k < m.ceil(n / 2):
		k += z
	print(k)


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


import math
s = input().split()
n = float(s[0])
m = int(s[1])
if m > n:
	print('-1')
else:
	x = math.ceil(n / 2)
	k = math.ceil(x / m)
	print(k * m)


(n, m) = map(int, input().split())
r = n % 2
resp = n // 2 + r
while resp <= n:
	if resp % m == 0:
		print(resp)
		break
	else:
		resp = resp + 1
if resp > n:
	print(-1)


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


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


a = list(map(int, input().split()))
b = a[0] // 2
c = a[0] % 2
step = b + c
if a[0] < a[1]:
	print('-1')
else:
	while True:
		if step % a[1] == 0:
			break
		else:
			step += 1
	print(step)


try:
	(n, m) = map(int, input().split())
	if n < m:
		print('-1')
	elif n == m:
		print(n)
	elif n % 2 == 0:
		val = n // 2
		while 1:
			if val % m == 0:
				break
			else:
				val += 1
		print(val)
	else:
		n = n - 1
		val = n // 2
		val += 1
		while 1:
			if val % m == 0:
				break
			else:
				val += 1
		print(val)
except EOFError:
	pass


(n, m) = map(int, input().split())
if m > n:
	print(-1)
else:
	ans = 10000000
	if n % 2 == 0:
		temp = n // 2
	else:
		temp = n // 2 + 1
	while n != temp - 1:
		if n % m == 0:
			ans = min(n, ans)
		n -= 1
	print(ans)


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	(n, m) = mint()
	if m > n:
		return -1
	ans = 10 ** 10
	for i in range(n + 1):
		for j in range(n + 1):
			if 2 * i + j == n and (i + j) % m == 0:
				ans = min(ans, i + j)
	return ans
print(solve())


(n, m) = map(int, input().split())
b = n // 2
target = n % m
current = b % m
if target <= current:
	shift = current - target
else:
	shift = m + current - target
if shift > b:
	print(-1)
else:
	b = b - shift
	a = n - 2 * b
	print(a + b)


st = input().split()
n = int(st[0])
m = int(st[1])
twos = n // 2
ones = n % 2
total = twos + ones
multi = total % m == 0
while twos > 0 and multi == False:
	twos -= 1
	ones += 2
	total += 1
	multi = total % m == 0
if multi:
	print(total)
else:
	print(-1)


anslist = []
list1 = [int(item) for item in input().split()]
dividend = list1[0]
divisor = list1[1]
if dividend < divisor:
	result = -1
elif dividend % 2 == 0:
	listofmul = list(range(int(dividend / 2), int(dividend + 1)))
	for item in listofmul:
		if item % divisor == 0:
			anslist.append(item)
	result = min(anslist)
else:
	listofmul = list(range(int((dividend + 1) / 2), int(dividend + 1)))
	for item in listofmul:
		if item % divisor == 0:
			anslist.append(item)
	result = min(anslist)
print(result)


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


import math
(n, m) = map(int, input().strip().split())
Min = math.ceil(n / 2)
Max = n
for i in range(Min, Max + 1):
	if i % m == 0:
		print(i)
		exit()
print(-1)


(n, m) = map(int, input().split())
if n < m:
	output = -1
else:
	i = (n + 1) // 2
	while i:
		if i % m == 0:
			output = i
			break
		i += 1
print(output)


(n, m) = map(int, input().split())
a2 = (n + 1) // 2
am = (a2 - 1) // m * m + m
print((am, -1)[am > n])


o = input().rstrip().split(' ')
a = int(o[0])
b = int(o[1])
if a < b:
	print(-1)
else:
	A = a // 2
	B = a % 2
	if (A + B) % b == 0:
		print(A + B)
	elif B == 0:
		C = 0
		for i in range(A, 100000000):
			if i % b == 0:
				break
			else:
				C += 1
		if C == 0:
			print(-1)
		elif C > A:
			print(-1)
		else:
			print(A + C)
	else:
		C = 0
		for i in range(A + B, 10000000000):
			if i % b == 0:
				break
			else:
				C += 1
		if C == 0:
			print(-1)
		elif C > A + B:
			print(-1)
		else:
			print(A + B + C)


(n, k) = map(int, input().split())
lo = (n + 1) // 2
hi = n
flag = False
for i in range(lo, hi + 1):
	if i % k == 0:
		flag = True
		print(i)
		break
if not flag:
	print('-1')


(n, m) = map(int, input().split())
v = m
while 2 * v < n:
	v += m
(two, one, flag) = (v, 0, 0)
while two >= 0 and one <= v:
	if two * 2 + one * 1 == n:
		print(v)
		flag = 1
		break
	two -= 1
	one += 1
if flag == 0:
	print(-1)


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, m) = read_ints()
	if n < m:
		print(-1)
		return
	(q, r) = divmod(n, 2 * m)
	ans = q * m
	if r:
		ans += m
	print(ans)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def dbg(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
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 read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

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

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
if n < m:
	print(-1)
	sys.exit(0)
answer = n // 2 + n % 2
if answer % m != 0:
	answer += m - answer % m
print(answer)


from math import ceil
(n, m) = map(int, input().strip().split())
p = 1
while True:
	y = 2 * m * p - n
	if y >= 0:
		break
	p += 1
x = (n - y) / 2
print(int(x + y) if x >= 0 and y >= 0 else -1)


def Main():
	(n, m) = map(int, input().split())
	nt = n // 2
	no = n % 2
	found = False
	while True:
		if (nt + no) % m == 0:
			found = True
			break
		if nt == 0:
			break
		nt -= 1
		no += 2
	if found == True:
		print(nt + no)
	else:
		print(-1)
Main()


from math import ceil
s = str(input())
temp = s.split()
n = int(temp[0])
m = int(temp[1])
min_steps = n // 2 + n % 2
steps = ceil(min_steps / m) * m
if m > n:
	print(-1)
else:
	print(steps)


from sys import stdin, maxsize
from collections import defaultdict
from math import ceil
(lines, line_index) = (stdin.readlines(), -1)
table = defaultdict(int)

def get_line():
	global lines, line_index
	line_index += 1
	return lines[line_index]

def main():
	(n, m) = [int(x) for x in get_line().split()]
	lower_bound = (n + 1) // 2
	ans = ceil(lower_bound / float(m)) * m
	if ans > n:
		ans = -1
	print(int(ans))
main()


(total, kelipatan) = map(int, input().split())
k = 0
if total < kelipatan:
	print(-1)
else:
	k = total / 2 % kelipatan
	if k == 0:
		print(int(total / 2))
	else:
		print(int(total / 2 + (kelipatan - k)))


from sys import stdin, stdout
(n, m) = stdin.readline().split()
(n, m) = (int(n), int(m))
if n < m:
	stdout.write('-1')
else:
	mini_steps = n // 2 + n % 2
	if mini_steps % m == 0:
		stdout.write(str(mini_steps))
	else:
		i = 0
		while m * i < mini_steps:
			i += 1
		stdout.write(str(m * i))


(n, m) = (int(x) for x in input().split())
if n < m:
	print(-1)
else:
	print((int((n - 0.5) / (2 * m)) + 1) * m)


(n, m) = map(int, input().split())
two = n // 2
one = n - two * 2
while two >= 0:
	if (two + one) % m == 0:
		print(two + one)
		exit(0)
	(two, one) = (two - 1, one + 2)
print(-1)


def f(l):
	(n, m) = l
	ms = (n + 1) // 2
	ds = (ms + m - 1) // m * m
	return -1 if ds > n else ds
l = list(map(int, input().split()))
print(f(l))


def main():
	(n, m) = [int(x) for x in input().split(' ')]
	res = 0
	while True:
		if n < 0:
			res = -1
			break
		q = n // 2
		r = n % 2
		if r != 0:
			res += 1
			n -= 1
			continue
		if (q + res) % m == 0:
			res += q
			break
		res += 1
		n -= 1
	print(res)
	return

def __starting_point():
	main()
__starting_point()


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


def sol():
	[n, m] = [int(x) for x in input().split()]
	num_moves = n // 2 if not n % 2 else n // 2 + 1
	if not num_moves % m:
		return num_moves
	num_moves += m - num_moves % m
	if num_moves > n:
		return -1
	return num_moves
print(sol())


(n, m) = map(int, input().split())
i = n // 2
j = n % 2
if n < m:
	print(-1)
else:
	while (i + j) % m != 0:
		i = i - 1
		j = j + 2
	print(i + j)


from math import ceil

def main():
	(n, m) = map(int, input().split())
	minSteps = ceil(n / 2)
	if m > n:
		print(-1)
		return
	print(ceil(minSteps / m) * m)
main()


(n, m) = list(map(int, input().split()))
f = True
if n >= m:
	if n % 2 == 0:
		k = n // 2
	else:
		k = n // 2 + 1
	for i in range(n):
		if (k + i) % m == 0:
			f = False
			print(k + i)
			break
if f:
	print(-1)


(step, base) = map(int, input().split())
maxstep = step
minstep = 0
if step & 1:
	minstep = int((step + 1) / 2)
else:
	minstep = int(step / 2)
IsFind = False
for item in range(minstep, maxstep + 1):
	if item % base == 0:
		print(item)
		IsFind = True
		break
	else:
		continue
if IsFind == False:
	print(-1)


(n, m) = map(int, input().split())
mov = n // 2 + n % 2
if n < m:
	print('-1')
elif mov % m == 0:
	print(mov)
else:
	a = mov
	c = 0
	while mov % m != 0:
		if c <= a:
			mov = mov + 1
			c = c + 1
		else:
			break
	if mov % m == 0:
		print(mov)
	else:
		print('-1')


(n, m) = map(int, input().split())
p = n
n = n // 2 + n % 2
y = True
for i in range(10):
	if n > p:
		break
	elif n % m == 0:
		print(n)
		y = False
		break
	n = n + 1
if y == True:
	print('-1')


from sys import stdin, stdout
input = stdin.readline
(n, m) = map(int, input().split())
if n < m:
	stdout.write('-1')
else:
	one = n % 2
	two = n // 2
	while two > 0:
		r = one + two
		if r % m == 0:
			stdout.write(str(r))
			exit(0)
		one += 2
		two -= 1
	r = one + two
	if r % m == 0:
		stdout.write(str(r))
	else:
		stdout.write('-1')


(n, m) = input().split()
n = int(n)
m = int(m)
r = 1
if n % 2 == 0:
	k = n // 2
else:
	k = n // 2 + 1
if k % m == 0:
	r = 2
	print(k)
else:
	while k < n:
		k += 1
		if k % m == 0:
			print(k)
			r = 0
			break
if r == 1:
	print('-1')


from math import ceil
a = input().split()
n = int(a[0])
m = int(a[1])
if n < m:
	print('-1')
else:
	print(m * ceil(ceil(n / 2) / m))


import math

def main():
	(n, m) = map(int, input().split())
	b = n // 2
	res = -1
	while b >= 0:
		a = n - 2 * b
		if (a + b) % m == 0:
			res = a + b
			break
		b -= 1
	print(res)
main()


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


(N, M) = map(int, input().split())
if M > N:
	print(-1)
else:
	if N % 2 == 0:
		b = N // 2
	else:
		b = N // 2 + 1
	for i in range(b, N + 1):
		if i % M == 0:
			print(i)
			break


(n, m) = map(int, input().split())
high = n
low = (n + 1) // 2
x = m
while x < low:
	x = x + m
if x >= low and x <= high:
	print(x)
else:
	print(-1)


(a, b) = map(int, input().split())
ans = (a + 1) // 2
while True:
	if ans > a:
		print(-1)
		break
	if ans % b == 0:
		print(ans)
		break
	ans += 1


(n, m) = map(int, input().split())
(down, top) = ((n + 1) // 2, n)
res = (down + m - 1) // m * m
if res <= top:
	print(res)
else:
	print(-1)


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


(n, m) = input().split()
n = int(n)
m = int(m)
maximum = n
if n % 2 == 0:
	minimum = int(n / 2)
else:
	minimum = int(n / 2) + 1
if m > n:
	print(-1)
else:
	for i in range(minimum, maximum + 1):
		if i % m == 0:
			print(i)
			break


(n, m) = map(int, input().split())
cnt = n // 2
t = n
if n % 2 != 0:
	cnt += 1
f = False
for i in range(cnt, t + 1):
	if i % m == 0:
		f = True
		print(i)
		break
if not f:
	print(-1)


z = input().split(' ')
n = int(z[0])
m = int(z[1])
min = int(n / 2) if n % 2 == 0 else int(n / 2) + 1
if m <= n:
	while True:
		if min % m == 0:
			print(str(min))
			break
		else:
			min += 1
else:
	print('-1')


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


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	if n < m:
		print(-1)
	else:
		initial = 0
		if n % 2 == 0:
			initial = n // 2
		else:
			initial = n // 2 + 1
		while initial % m != 0:
			initial += 1
		print(initial)
solve()


(n, m) = map(int, input().split())
tot = n // 2 + n % 2
flag = True
while tot <= n:
	if tot % m == 0:
		flag = False
		break
	else:
		tot += 1
if flag:
	print('-1')
else:
	print(tot)


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

def main():
	inilen = sum(divmod(n, 2))
	while inilen <= n:
		if inilen % m == 0:
			break
		inilen += 1
	else:
		print('-1')
		return
	print(inilen)
	return
main()


import math
x = [int(i) for i in input().split()]
n = x[0]
m = x[1]
if n % 2 == 0:
	s = math.ceil(n // 2 / m)
else:
	s = math.ceil((n + 1) // 2 / m)
if s * m <= n:
	print(s * m)
else:
	print(-1)


(step, mul) = map(int, input().split())
temp = mul
if step < mul:
	print(-1)
else:
	while True:
		if temp * 2 >= step:
			print(temp)
			break
		else:
			temp += mul


def main():
	(totalStairs, multiple) = input().split()
	(totalStairs, multiple) = (int(totalStairs), int(multiple))
	if totalStairs % 2 == 0:
		base = totalStairs / 2
		base = int(base)
	else:
		base = totalStairs / 2 + 0.5
		base = int(base)
	for i in range(base, totalStairs + 1):
		if i % multiple == 0:
			print(i)
			return ()
	print(-1)
	return ()
main()


from math import ceil
(a, b) = [int(x) for x in input().split()]
if a < b:
	print(-1)
else:
	print(ceil(a / (2 * b)) * b)


(a, b) = map(int, input().split())
mina = 10001
for ones in range(0, a + 1):
	twos = (a - ones) // 2
	if 2 * twos + ones == a and (twos + ones) % b == 0:
		mina = min(twos + ones, mina)
print(mina if mina != 10001 else '-1')


(n, m) = list(map(int, input().split()))
a = n
c = 0
x = 0
while n >= 0:
	q = n // 2
	r = n % 2
	c = q + r + (a - n)
	if c % m == 0:
		print(c)
		x += 1
		break
	else:
		n -= 2
if x == 0:
	print(-1)


(n, m) = list(map(int, input().split()))
pairs = 0
singl = 0
res = 0
if n == m:
	res = m
elif m < n:
	pairs = n // 2
	singl = n - pairs * 2
	while pairs > 0 and (pairs + singl) % m != 0:
		pairs -= 1
		singl += 2
if (pairs + singl) % m == 0 and m < n:
	res = pairs + singl
elif res == 0:
	res = -1
print(res)


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


(n, m) = input().split()
(n, m) = (int(n), int(m))
lis = []
for b in range(n // 2 + 1):
	if (n - b) % m == 0:
		lis.append(n - b)
if lis == []:
	print('-1')
else:
	print(min(lis))


line = [int(i) for i in str(input()).split()]
n = line[0]
m = line[1]
minsteps = n // 2 + n % 2
while True:
	if minsteps > n:
		print(-1)
		break
	elif minsteps % m == 0:
		print(minsteps)
		break
	else:
		minsteps += 1


(x, y) = map(int, input().split())
z = int(x // 2)
w = int(x % 2)
t = z + w
if x >= y:
	if t % y != 0:
		while t % y != 0:
			t = t + 1
		print(t)
	else:
		print(t)
else:
	print(-1)


def solve(n, m):
	_min = int(n / 2) + n % 2
	for i in range(_min, n + 1):
		if i % m == 0:
			return i
	return -1

def test():
	assert solve(10, 2) == 6
	assert solve(3, 5) == -1
test()
(n, m) = [int(x) for x in input().split()]
print(solve(n, m))


(n, m) = map(int, input().split())
if n % 2 == 0:
	min = n // 2
else:
	min = n // 2 + 1
max = n
bool = 0
for i in range(min, max + 1):
	if i % m == 0:
		print(i)
		bool = 1
		break
if bool == 0:
	print(-1)


import math
(n, m) = map(int, input().split(' '))
a = int(math.ceil(n / 2))
b = n
min = -1
if m == n:
	min = m
else:
	for i in range(a, n):
		if i % m == 0:
			min = i
			break
print(min)


(a, b) = map(int, input().split())
from math import ceil
if a < b:
	print(-1)
else:
	for i in range(ceil(a / 2), 50000):
		if i % b == 0:
			print(i)
			break


(n, m) = map(int, input().split())
l1 = []
k = n // 2
i = 0
if n < m:
	a = -1
else:
	if n % 2 == 0:
		a = int(n / 2)
	else:
		a = int(n / 2) + 1
	while a % m != 0:
		a += 1
print(a)


(n, m) = map(int, input().split())
k = n // 2
res = -1
if n >= m:
	if n % 2 != 0:
		k += 1
	while k <= n and k % m != 0:
		k += 1
	if k % m == 0:
		res = k
print(res)


import math
(a, b) = list(map(int, input().split()))
r = math.ceil(a / 2)
flag = 0
for i in range(r, a + 1):
	if i % b == 0:
		flag = 1
		break
if flag == 1:
	print(i)
else:
	print(-1)


(a, b) = map(int, input().split())
c = a // 2 + 1 if a % 2 != 0 else a // 2
boo = False
for i in range(c, a + 1):
	if i % b == 0:
		boo = True
		break
print(i if boo else -1)


import sys
import math
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())
in_first = list(invr())
n = in_first[0]
m = in_first[1]
min = math.floor(n / 2)
print_thing = -1
if n % 2 != 0:
	min += 1
while min <= n:
	if min % m == 0:
		print_thing = min
		break
	min += 1
print(print_thing)


def ans(nm):
	n = nm[0]
	m = nm[1]
	if n < m:
		return -1
	elif n == m:
		return n
	else:
		if n % 2 == 0:
			move = n // 2
		else:
			move = n // 2 + 1
		if move % m:
			move = move // m + 1
			move = move * m
	return move
nm = list(map(int, input().strip().split()))
print(ans(nm))


(n, m) = map(int, input().split())
i = 0
ans = -1
while 2 * i <= n:
	if (n - i) % m == 0:
		if ans == -1:
			ans = n - i
		else:
			ans = min(ans, n - i)
	i = i + 1
print(ans)


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


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


import sys
(n, m) = [int(x) for x in input().split()]
ans = 10000000
for x in range(0, n + 1):
	if 2 * x <= n:
		for y in range(0, n + 1):
			if 2 * x + y == n:
				if (x + y) % m == 0:
					ans = min(ans, x + y)
if ans == 10000000:
	print(-1)
else:
	print(ans)


def DoraemonAndStairs():
	(n, m) = map(int, input().split())
	if n < m:
		print(-1)
		return None
	moves = n // 2 + n % 2
	while moves % m != 0 and moves <= n:
		moves += 1
	print(moves)
	return None

def main():
	DoraemonAndStairs()
main()


def func(p, m, n):
	w = p
	while w % m != 0 and w <= n:
		w += 1
	if w <= n:
		return w
	else:
		return -1
l = input().split()
n = int(l[0])
m = int(l[1])
if n % 2 == 0:
	p = int(n / 2)
else:
	p = int(n / 2) + 1
print(func(p, m, n))


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


(n, m) = map(int, input().split())
if n < m:
	print('-1')
	exit()
twos = n // 2
ones = n - 2 * twos
while twos > 0:
	if (twos + ones) % m == 0:
		break
	twos -= 1
	ones += 2
print(twos + ones)


(n, b) = [int(i) for i in input().split()]
if n % 2 != 0:
	y = n // 2 + 1
else:
	y = n // 2
while y % b != 0:
	y += 1
if y > n:
	print(-1)
else:
	print(y)


(stair, amount) = [int(i) for i in input().split()]
if amount > stair:
	print(-1)
else:
	if stair % 2 == 1:
		stair += 1
	stair = int(stair / 2)
	while amount != stair:
		if stair % amount == 0:
			amount = stair
		else:
			stair += 1
	print(amount)


(n, m) = map(int, input().split())
a = (n + 1) // 2
b = (a - 1) // m * m + m
print([b, -1][b > n])


import math
(n, m) = input().split()
n = int(n, 10)
m = int(m, 10)
s = 0
if n < m:
	print(-1)
else:
	s = math.ceil(n / 2)
	if s % m == 0:
		print(s)
	else:
		print(m * math.ceil(s / m))


l = []
(x, y) = map(int, input().split())
if x % 2 == 0:
	l += [2] * int(x / 2)
	if len(l) % y == 0:
		print(len(l))
	else:
		while len(l) % y != 0:
			if l.count(2) == 0:
				print('-1')
				exit()
			l.remove(2)
			l += [1] * 2
		print(len(l))
else:
	l += [2] * int(x / 2)
	l.append(1)
	if len(l) % y == 0:
		print(len(l))
	else:
		while len(l) % y != 0:
			if l.count(2) == 0:
				print('-1')
				exit()
			l.remove(2)
			l += [1] * 2
		print(len(l))


import math
(n, m) = [int(i) for i in input().split()]
mi = math.ceil(n / 2)
for i in range(mi, n + 1):
	if i % m == 0:
		print(i)
		break
else:
	print(-1)


(n, m) = list(map(int, input().split(' ')))
high = n
twos = n // 2
low = twos + n - 2 * twos
b = 0
while b < low:
	b += m
if b > high:
	print(-1)
else:
	print(b)


x = input().split(' ')
a = int(x[0])
b = int(x[1])
if a < b:
	print(-1)
else:
	import math
	start = math.ceil(a / 2)
	for i in range(start, a + 1):
		if i % b == 0:
			print(i)
			break


import math
(n, m) = map(int, input().split())
if n < m:
	print('-1')
else:
	steps = math.ceil(n / 2)
	if steps % m == 0:
		print(steps)
	else:
		ans = m - steps % m + steps
		print(ans)


(n, m) = map(int, input().split())
min = n
for b in range(n // 2, -1, -1):
	a = n - 2 * b
	s = a + b
	if s % m == 0 and s < min:
		min = s
if min % m == 0:
	print(min)
else:
	print(-1)


import math
l = list(map(int, input().strip().split()))
a = l[0]
b = l[1]
c = math.ceil(a / 2)
flag = 0
for i in range(c, a + 1):
	if i % b == 0:
		print(i)
		flag = 1
		break
if flag == 0:
	print(-1)


(n, m) = map(int, input().split())
minimal_moves = n // 2 + n % 2
if minimal_moves % m != 0:
	ans = minimal_moves + m - minimal_moves % m
else:
	ans = minimal_moves
if n < m:
	print(-1)
else:
	print(ans)


import math
t = input()
temp = t.split()
n = int(temp[0])
m = int(temp[1])
divident = math.floor(n / 2)
modulus = n % 2
minSteps = divident + modulus
modulus2 = minSteps % m
if m > n:
	result = -1
elif modulus2 == 0:
	result = minSteps
else:
	result = minSteps + (m - modulus2)
print(result)


def sol(a, b):
	if b > a:
		x = -1
	else:
		if a % 2 == 0:
			x = a // 2
		else:
			x = a // 2 + 1
		while x % b != 0:
			x += 1
	return x
(a, b) = map(int, input().split())
print(sol(a, b))


import sys
import collections
(num, m) = [int(x) for x in sys.stdin.readline()[:-1].split(' ')]
flag = 0
if num % 2 == 0:
	tot = num / 2
else:
	tot = (num - 1) / 2 + 1
while tot % m != 0:
	tot += 1
	if tot > num:
		flag = 1
		break
if flag:
	print(-1)
else:
	print(int(tot))


import sys
inf = float('inf')
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, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

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()
ans = -1
(n, m) = get_ints()
if n & 1:
	start = n // 2 + 1
else:
	start = n // 2
end = n
for i in range(start, end + 1):
	if i % m == 0:
		ans = i
		flag = 1
		break
print(ans)


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


(n, m) = map(int, input().split())
if n < m:
	print('-1')
elif n == m:
	print(n)
else:
	num = n // 2
	rem = n % 2
	if rem == 0:
		while num % m != 0:
			num = num + 1
		print(num)
	elif rem > 0:
		num1 = num + rem
		while num1 % m != 0:
			num1 = num1 + 1
		print(num1)


(n, m) = map(int, input().split())
ok = False
for step2 in range(n // 2, -1, -1):
	step = step2 + (n - 2 * step2)
	if step % m == 0:
		print(step)
		ok = True
		break
if not ok:
	print(-1)


l = input().split()
n = int(l[0])
m = int(l[1])
if n % 2 == 0:
	o = int(n / 2)
else:
	o = int(n / 2) + 1
if m > n:
	print(-1)
elif o <= m:
	print(m)
else:
	y = True
	while y:
		if o % m == 0:
			y = False
			break
		o += 1
	print(o)


from math import ceil
from math import floor
(n, m) = [int(x) for x in input().split()]
i = ceil(n / 2)
while i <= n:
	nprime = i
	if 2 * nprime - n >= 0 and 2 * nprime - n <= n and (-(nprime - n) >= 0) and (-(nprime - n) <= floor(n / 2)):
		if nprime % m == 0:
			print(nprime)
			break
	i += 1
else:
	print(-1)


import math
(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	steps = n // 2 + n % 2
	min_steps = math.ceil(steps / m) * m
	print(min_steps)


import math
(a, b) = map(int, input().split())
most = a
least = math.ceil(a / 2)
flag = 0
for i in range(least, most + 1):
	if i % b == 0:
		print(i)
		flag = 1
		break
if a == 0:
	print(0)
elif flag == 0:
	print(-1)


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

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 vars():
	return map(int, input().split())

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

def main():
	(n, m) = vars()
	l = math.ceil(n / 2)
	r = n
	steps = l
	for i in range(l, r + 1):
		if steps % m == 0:
			break
		steps += 1
	if steps > r:
		print(-1)
	else:
		print(steps)
t = 1
for _ in range(t):
	main()


__author__ = 'hamed1soleimani'
import math
ipt = input().split()
m = int(ipt[1])
n = int(ipt[0])
f = False
for i in range(math.ceil(n / 2), n + 1):
	if i % m == 0:
		print(i)
		f = True
		break
if not f:
	print(-1)


import math
(n, m) = map(int, input().split())
d = -1
x = 0
for i in range(math.ceil(n / 2), n + 1, 1):
	if i % m == 0 and x == 0:
		d = i
		x = 1
print(d)


(n, m) = map(int, input().split())
w = 3
if n % 2 == 0:
	q = n // 2
else:
	q = n // 2 + 1
for i in range(q, n + 1):
	if i % m == 0:
		w = 5
		print(i)
		break
if w != 5:
	print('-1')


(x, y) = map(int, input().split())
a = 0
while 1:
	if x % 2 == 0:
		if x < y:
			print('-1')
			break
		if (x // 2 + a) % y == 0:
			print(x // 2 + a)
			break
		else:
			a += 1
	else:
		if x < y:
			print('-1')
			break
		if (x // 2 + 1 + a) % y == 0:
			print(x // 2 + a + 1)
			break
		else:
			a += 1


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


def rii():
	return [int(x) for x in input().split()]
(n, m) = rii()
ans = float('inf')
for a in range(n + 1):
	b = (n - a) / 2
	if a + 2 * b == float(n) and (a + b) % m == 0:
		ans = min(ans, int(a + b))
print(ans if ans != float('inf') else -1)


import math
(n, m) = map(int, input().split())
s1 = n // 2
s2 = n % 2
if (s1 + s2) % m != 0:
	while s1 > -1 and (s1 + s2) % m:
		s1 -= 1
		s2 += 2
print(s1 + s2) if s1 >= 0 else print(-1)


s = input().split(' ')
n = int(s[0])
m = int(s[1])
l = (n + 1) // 2
a = (l + m - 1) // m * m
if a > n:
	a = -1
print(a)


(stairs, nofMoves) = map(int, input().split())
one = (stairs + 1) // 2 + (nofMoves - 1)
two = one // nofMoves * nofMoves
if stairs >= two:
	print(two)
else:
	print(-1)


(n, m) = map(int, input().split())
maxstep = n
minstep = (n + 1) // 2
maxres = maxstep // m
minres = minstep // m
if maxres == minres and maxstep % m != 0 and (minstep % m != 0):
	print(-1)
elif minstep % m == 0:
	print(minstep)
else:
	print((minstep // m + 1) * m)


(n, m) = [int(i) for i in input().split()]
if n % 2 == 0:
	x = list(range(n // 2, n + 1))
else:
	x = list(range(n // 2 + 1, n + 1))
try:
	ind = [i % m == 0 for i in x].index(True)
	print(x[ind])
except:
	print(-1)


def steps(n, m):
	if n < m:
		print('-1')
		return
	if n == m:
		print(n)
		return
	else:
		if n % 2 == 0:
			ans = n / 2
		else:
			ans = 1 + (n - 1) / 2
		if ans % m == 0:
			print(int(ans))
		else:
			while ans % m != 0:
				ans = ans + 1
			print(int(ans))
a = []
b = []
(a, b) = input().split()
a = int(a)
b = int(b)
steps(a, b)


(n, m) = (int(x) for x in input().split())
for y in range(n // 2, -1, -1):
	if (n - y) % m == 0:
		print(n - y)
		break
else:
	print(-1)


(n, m) = [int(x) for x in input().split()]
minSteps = 0
maxSteps = n
check = True
if n % 2 == 0:
	minSteps = int(n / 2)
else:
	minSteps = int(n / 2) + 1
for i in range(minSteps, maxSteps + 1):
	if i % m == 0:
		print(i)
		check = False
		break
if check:
	print(-1)


(n, m) = map(int, input().split())
l = n // 2 + n % 2
r = n
minMoves = -1
for x in range(l, r + 1):
	if x % m == 0:
		minMoves = x
		break
print(minMoves)


from sys import stdin
(n, m) = map(int, stdin.readline().split())
if n == 0:
	print(0)
elif n < m:
	print(-1)
else:
	a = n // 2 + n % 2
	while a % m != 0 and a <= n:
		a += 1
	print(a)


inp = list(map(int, input().split()))
n = inp[0]
m = inp[1]
if n < m:
	print('-1')
else:
	k = 0
	while n < k * m or 2 * k * m < n:
		k += 1
	print(k * m)


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	q = n // 2
	r = n % 2
	c = q + r
	if c % m == 0:
		print(c)
	else:
		i = 1
		while q != 0 and c % m != 0:
			q -= i
			r += i * 2
			c = q + r
		if c % m == 0:
			print(c)
		else:
			print(-1)


(n, m) = map(int, input().split(' '))
res = n + 1
for i in range(n):
	if (i + n - 2 * i) % m == 0 and n - 2 * i >= 0:
		res = min(res, i + n - 2 * i)
if res == n + 1:
	print(-1)
else:
	print(res)


from math import ceil
(n, m) = map(int, input().split())
p = ceil(n / 2)
f = False
for i in range(p, n + 1):
	if not f and i % m == 0:
		print(i)
		f = True
if not f:
	print(-1)


b = [int(b) for b in input().split()]
n = b[0]
m = b[1]
count = 0
if m <= n:
	if n % 2 == 0:
		k1 = n // 2
		if k1 % m == 0:
			print(k1)
		else:
			rem = k1 % m
			print(k1 + m - rem)
	else:
		k1 = (n - 1) // 2 + 1
		if k1 % m == 0:
			print(k1)
		else:
			rem = k1 % m
			print(k1 + m - rem)
else:
	print(-1)


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


(n, m) = list(map(int, input().split()))
i = n // 2 + n % 2
j = n
d = -1
for k in range(i, j + 1):
	if k % m == 0:
		d = k
		break
print(d)


(n, m) = [int(s) for s in input().split()]
step_max = n
step_min = n // 2 + n % 2
s = 0
if n < m:
	print(-1)
else:
	while step_min <= step_max and s == 0:
		if step_min % m == 0:
			s = step_min
		step_min += 1
	print(s)


def stairs(n, m):
	if m > n:
		return -1
	else:
		if n % 2 == 0:
			steps = n // 2
		else:
			steps = n // 2 + 1
		while steps % m != 0:
			steps += 1
	return steps
(n, m) = map(int, input().split())
print(stairs(n, m))


(n, m) = map(int, input().split())
if n % 2 == 0:
	high = n // 2
else:
	high = n // 2 + 1
if high % m == 0:
	div = high // m
else:
	div = high // m + 1
if m * div <= n:
	print(m * div)
else:
	print(-1)


from math import *
(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	if n % 2 == 0:
		moves = int(n / 2)
	else:
		moves = floor(n / 2) + 1
	if moves % m == 0:
		print(moves)
	else:
		c = ceil(moves / m)
		print(c * m)


import math
input_s = input().split()
n = int(input_s[0])
m = int(input_s[1])
min_n = n // 2 + (0 if n % 2 == 0 else 1)
result = -1
for i in range(min_n, n + 1):
	if i % m == 0:
		result = i
		break
print(result)


(N, M) = map(int, input().split())
ans = -1
min = N // 2
if N % 2 != 0:
	min += 1
for i in range(min, N + 1):
	if i % M == 0:
		ans = i
		break
print(ans)


def solve(a, b):
	big = float('inf')
	small = float('-inf')
	if a < b:
		return -1
	twos = a // 2
	ones = a % 2
	moves = twos + ones
	if moves % b == 0:
		return moves
	return moves + (b - moves % b)

def main():
	d = input()
	d = [int(i) for i in d.split()]
	a = d[0]
	b = d[1]
	ans = solve(a, b)
	print(ans)
main()


from sys import stdin
(n, m) = [int(c) for c in stdin.readline().split()]
min = (n + 1) // 2
max = n
answer = -1
for i in range(min, max + 1, 1):
	if i % m == 0:
		answer = i
		break
print(answer)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, M) = map(int, input().split())
minStep = N // 2 if N % 2 == 0 else N // 2 + 1
for step in range(minStep, N + 1):
	if step % M == 0:
		print(step)
		exit(0)
print(-1)


import math
l = list(map(int, input().split(' ')))
n = l[0]
m = l[1]
total = 0
for x in range(0, n + 1):
	for y in range(0, int(n / 2) + 1):
		if ((x + y) % m == 0 and x + 2 * y) == n:
			total = 1
			print(x + y)
			break
	if total == 1:
		break
if total == 0:
	print('-1')


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


args = [int(x) for x in input().split(' ')]
n = args[0]
m = args[1]
if m > n:
	print('-1')
else:
	steps = n // 2
	if n % 2 == 1:
		steps += 1
	if steps % m != 0:
		steps += m - steps % m
	print(steps)


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


from math import ceil
(n, m) = [int(i) for i in input().split()]
(prevSteps, leftSteps) = (n // 2, n % 2)
while (prevSteps + leftSteps) % m:
	prevSteps = prevSteps - 1
	leftSteps = n - 2 * prevSteps
if prevSteps >= 0 and leftSteps >= 0:
	print(prevSteps + leftSteps)
else:
	print(-1)


(n, m) = input().split()
n = int(n)
m = int(m)
ans = -1
if n >= m:
	temp = n // 2
	if temp % m == 0 and n % 2 == 0:
		ans = temp
	else:
		temp += 1
		while temp % m != 0:
			temp += 1
		ans = temp
print(ans)


def nums_ways(n, m):
	if m > n:
		return -1
	else:
		if n % 2 == 0:
			c = n // 2
		else:
			c = n // 2 + 1
		while c % m != 0:
			c += 1
	return c
(n, m) = map(int, input().split())
print(nums_ways(n, m))


def dreamoon_and_stairs(n, m):
	k = n // 2
	d = []
	for i in range(0, k + 1):
		if (n - i) % m == 0:
			d.append(n - i)
	if len(d) <= 0:
		return -1
	else:
		return min(d)
f = lambda : map(int, input().split())
(s, t) = f()
print(dreamoon_and_stairs(s, t))


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


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


(n, m) = map(int, input().split())
if m > n:
	print(-1)
else:
	for a in range(0, n + 1):
		if (n - a) % 2 == 0 and (a + (n - a) / 2) % m == 0:
			print(int(a + (n - a) / 2))
			break


Nm = [int(x) for x in input().split()]
(N, m) = (Nm[0], Nm[1])
if N % 2 == 0:
	M = N // 2
else:
	M = N // 2 + 1
num = []
for i in range(M, N + 1):
	num.append(i)
filt = list(filter(lambda x: x % m == 0, num))
if filt == []:
	print(-1)
else:
	print(filt[0])


(n, m) = [int(x) for x in input().split()]
a = n / 2
if m > n:
	print(-1)
else:
	for k in range(1, 10000):
		if k * m >= a and k * m <= n:
			print(k * m)
			break


from math import ceil
(n, m) = [int(i) for i in input().split()]
minimum_moves = ceil(n / 2)
minimum_multiple = ceil(minimum_moves / m) * m
if minimum_multiple <= n:
	print(minimum_multiple)
else:
	print(-1)


(a, b) = map(int, input().split())
if a % 2 == 0:
	c = a // 2
else:
	c = a // 2 + 1
if a < b:
	print('-1')
else:
	for i in range(c, 1000001):
		if i % b == 0:
			print(i)
			break


import math
(n, m) = map(int, input().split())
k = math.ceil(n / 2)
for i in range(k, n + 1):
	if i % m == 0:
		print(i)
		exit(0)
print(-1)


(n, m) = [int(i) for i in input().split()]
for i in range(int(n / 2 + 0.9999), n + 1):
	if i % m == 0:
		print(i)
		break
else:
	print(-1)


line = input().split()
n = int(line[0])
m = int(line[1])
cnt = 0
min = n // 2 + n % 2
if n < m:
	print(-1)
elif min % m == 0:
	print(min)
else:
	c = min
	while c % m != 0:
		c = c + 1
	print(c)


import math
(n, m) = [int(i) for i in input().split()]
s = 0
if n < m:
	print('-1')
	exit()
else:
	a = math.floor(n / 2)
	s += n - a
	while s > 0:
		if s % m == 0:
			print(s)
			exit()
		s += 1


(n, m) = map(int, input().split())
if m > n:
	print(-1)
elif n > m:
	if n % 2 == 0:
		for i in range(n, 1, -2):
			s = i // 2
			x = n - s * 2
			if (s + x) % m == 0:
				print(s + x)
				break
	else:
		for i in range(n - 1, 1, -2):
			s = i // 2
			x = n - s * 2
			if (s + x) % m == 0:
				print(s + x)
				break
elif n == m:
	print(n)


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


(n, m) = map(int, input().split())
if n % 2 == 0:
	maxx = n // 2
else:
	maxx = n // 2 + 1
c = 0
for j in range(maxx, n + 1):
	if j % m == 0:
		c = 1
		break
if c == 1:
	print(j)
else:
	print(-1)


inp = tuple(map(int, input().split(' ')))
(n, m) = inp
s1 = n % 2
s2 = n // 2
while (s1 + s2) % m != 0 and s2 > 0:
	s2 -= 1
	s1 += 2
if s2 == 0 and s1 % m != 0:
	print(-1)
else:
	print(s1 + s2)


import math
(n, m) = map(int, input().split(' '))
lb = math.ceil(n / 2)
ans = math.ceil(lb / m) * m
if ans > n:
	print('-1')
else:
	print(ans)


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


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


import math
(n, m) = list(map(int, input().split()))
res = -1
ans = n // 2 + n % 2
while ans < n + 1:
	if ans % m == 0:
		res = ans
		break
	ans += 1
if n < m:
	print('-1')
else:
	print(res)


import math
(n, m) = map(int, input().split())
arr = [2] * int(math.ceil(n / 2))
if n % 2:
	arr[len(arr) - 1] = 1
(k, t) = (arr.count(2), len(arr))
check = True
while t % m != 0 and k > 0:
	check = False
	t += 1
	k -= 1
	if k == 0 and t % m != 0:
		print(-1)
		break
else:
	print(t if not check or not t % m else -1)


def main():
	x = [int(y) for y in input().split()]
	n = x[0]
	m = x[1]
	suma = 0
	res = []
	while suma <= n:
		suma += 2
		res.append(2)
	a = len(res)
	while suma > n:
		res.pop()
		if suma - 2 == n:
			suma -= 2
			break
		res.append(1)
		suma -= 1
	while len(res) % m != 0 and a != 0:
		a -= 1
		res.pop()
		res.append(1)
		res.append(1)
	if a == 0:
		print(-1)
	else:
		print(len(res))
main()


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


(n, m) = tuple(map(int, input().split()))
for i in range(1, n // m + 1):
	k = i * m
	x = n - k
	y = 2 * k - n
	if x >= 0 and y >= 0:
		print(x + y)
		break
else:
	print('-1')


(n, m) = map(int, input().split())
divisors = []
test = 0
while test != n:
	if n - test >= 2:
		test = test + 2
		divisors.append(2)
	elif n - test == 1:
		test = test + 1
		divisors.append(1)
finished = False
stillPossible = True
while finished == False and stillPossible == True:
	if len(divisors) % m == 0:
		print(len(divisors))
		finished = True
	elif divisors[0] == 2:
		divisors.remove(divisors[0])
		divisors.append(1)
		divisors.append(1)
	else:
		print(-1)
		stillPossible == False
		raise SystemExit(0)


(n, m) = list(map(int, input().split()))
(s, flag) = (n // 2, 0)
if n > 2:
	if n % s != 0:
		s += 1
else:
	s += 1
if n < m:
	flag = 0
else:
	while s <= n:
		if s % m == 0:
			flag = 1
			break
		s += 1
if flag == 0:
	print('-1')
else:
	print(s)


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


import math
(n, m) = map(int, input().split())
MAX = n
MIN = math.ceil(n / 2)
a = 0
for i in range(n // m + 1):
	if not i * m < MIN and (not i * m > MAX):
		print(i * m)
		a = 1
		break
if a == 0:
	print(-1)


(ax, bx) = input().split()
n = int(ax)
m = int(bx)
mat2 = int(n / 2)
mat1 = n % 2
while mat2 != 0 and (mat1 + mat2) % m != 0:
	mat2 -= 1
	mat1 += 2
if (mat1 + mat2) % m == 0:
	print(mat1 + mat2)
else:
	print(-1)


(n, k) = map(int, input().split())
if k > n:
	print(-1)
else:
	ans = n // 2
	rem = n % 2
	if ans < k:
		ans = k
	elif ans == k and rem != 0:
		ans = k * 2
	elif ans > k:
		if ans % k == 0 and rem == 0:
			ans = ans
		else:
			kk = k
			while ans + rem > k:
				k += kk
			ans = k
	print(ans)


(n, m) = list(map(int, input().split()))
Min = (n + 1) // 2
while Min <= n and Min % m != 0:
	Min += 1
if Min <= n:
	print(Min)
else:
	print(-1)


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


n = list(map(int, input().split()))
(a, b) = (n[0], n[1])
k = a / 2
if a < b:
	print(-1)
elif k % 1 == 0:
	for i in range(int(k) + 1):
		if k % b == 0:
			break
		else:
			k = k + 1
	print(int(k))
else:
	k = int(k) + 1
	for i in range(int(k) + 1):
		if k % b == 0:
			break
		else:
			k = k + 1
	print(k)


(x, y) = map(int, input().split())
i = 0
if x >= y:
	k = y
	while k <= x:
		if x - k <= k:
			i = k
			break
		k += y
	print(i)
else:
	print(-1)


def main(n, m):
	if n < m:
		return -1
	temp = int(n / 2) + n % 2
	while temp % m != 0 and temp < n:
		temp = temp + 1
	return temp if temp % m == 0 else -1
(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
print(main(n, m))


from math import ceil as ce
(n, m) = map(int, input().split())
t = ce(n / 2)
if t <= m <= n:
	print(m)
elif m > n:
	print(-1)
else:
	for i in range(t, n + 1):
		if i % m == 0:
			print(i)
			break


(n, m) = list(map(int, input().split()))
li = []
flag = True
while n != 0:
	if n % 2 == 0:
		n -= 2
		li.append(2)
	else:
		n -= 1
		li.append(1)
while flag:
	if len(li) % m == 0:
		flag = False
		break
	if 2 not in li:
		break
	else:
		del li[0]
		li.append(1)
		li.append(1)
if flag:
	print(-1)
else:
	print(len(li))


(a, b) = map(int, input().split())
count = 1
if a < b:
	print(-1)
elif a == b:
	print(a)
else:
	twos = a // 2
	ones = a % 2
	while twos != 0:
		if (twos + ones) % b == 0:
			count = 0
			break
		twos -= 1
		ones += 2
	if count == 0:
		print(twos + ones)
	else:
		print(-1)


(a, b) = map(int, input().split(' '))
k = 0
co = a // 2 + a % 2
while True:
	if co % b == 0:
		print(co)
		k = 1
		break
	else:
		if co == a // 2 * 2 + a % 2:
			break
		co += 1
if k == 0:
	print(-1)


(a, b) = map(int, input().split())
if a < b:
	print(-1)
else:
	mini = a // 2 + a % 2
	i = 0
	while True:
		if mini <= b * i:
			print(b * i)
			break
		i += 1


(n, m) = map(int, input().split())
minimum = n + 1
for x in range(n + 1):
	if (n - x) % 2 == 0:
		if (x + (n - x) / 2) % m == 0:
			if x + (n - x) / 2 < minimum:
				minimum = int(x + (n - x) / 2)
if minimum != n + 1:
	print(minimum)
else:
	print(-1)


def round_off(n):
	n1 = int(n)
	fp = n - n1
	if fp > 0.5:
		return n1 + 1
	else:
		return n1
a = list((int(x) for x in input().split()))
n = a[0]
m = a[1]
if n < m:
	print(-1)
elif n == m:
	print(n)
elif n % 2 != 0:
	for i in range(n // 2 + 1, n):
		if i % m == 0:
			print(i)
			break
		else:
			pass
else:
	for i in range(n // 2, n):
		if i % m == 0:
			print(i)
			break
		else:
			pass


def main():
	(n, m) = [int(x) for x in input().split(' ')]
	if m > n or n <= 0:
		print(-1)
		return -1
	t = n // 2
	if n % 2 != 0:
		t += 1
	while t % m != 0:
		t += 1
	print(t)
main()


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


(n, m) = map(int, input().split())
if m > n:
	print(-1)
else:
	moves = n // 2
	off = 0
	if n % 2 != 0:
		off = 1
	if (moves + off) % m == 0:
		print(moves + off)
	else:
		num = (moves + off) % m
		if moves - (m - num) >= 0:
			moves += m - num
			print(moves + off)
		else:
			print(-1)


(n, m) = map(int, input().split())
from sys import maxsize
if n < m:
	print(-1)
else:
	if n % 2 == 0:
		tots = n // 2
	else:
		tots = n // 2 + 1
	while tots % m != 0:
		tots += 1
	print(tots)


import sys
(n, m) = [int(a) for a in input().split()]
twos = n // 2
ones = n % 2
while (twos + ones) % m != 0 and twos > 0:
	twos -= 1
	ones += 2
if (twos + ones) % m != 0:
	print(-1)
else:
	print(twos + ones)


def dreaMoon(n, m):
	j = 0
	while n > 0:
		s = n // 2 + n % 2 + j
		if s % m == 0:
			return s
		j += 1
		n -= 1
	return -1
(n, m) = map(int, input().split())
print(dreaMoon(n, m))


import math
(n, m) = map(int, input().split())
if m > n:
	print(-1)
	exit()
elif m == n:
	print(n)
	exit()
else:
	mi = math.ceil(n / 2)
	app = 0
	if mi % m != 0:
		app = m - mi % m
	ans = mi + app
	print(ans)


import math
(n, m) = map(int, input().split())
_min = math.ceil(n / 2)
_max = n
if _min % m == 0:
	print(_min)
elif _min + (m - _min % m) <= _max:
	print(_min + (m - _min % m))
else:
	print('-1')


def a():
	(n, m) = map(int, input().split())
	min = 99999
	for i in range(n + 1):
		for j in range(n + 1):
			if (i + 2 * j == n or i * 2 + j == n) and (i + j) % m == 0:
				if i + j < min:
					min = i + j
	if min != 99999:
		print(min)
		return
	print(-1)
	return
a()


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	import math
	ss = math.ceil(n / (2 * m)) * m
	print(ss)


(n, m) = map(int, input().split())
c = 0
if n % 2 == 0:
	p = n // 2
else:
	p = (n - 1) // 2 + 1
while p <= n:
	if p % m == 0:
		print(p)
		c = 1
		break
	p += 1
if c == 0:
	print(-1)


R = lambda : map(int, input().split())
(n, m) = R()
a = n - n // 2
print([a + -a % m, -1][n < m])


(n, m) = [int(x) for x in input().split()]
c = 0
for i in range(n // 2 + n % 2, n + 1):
	if i % m == 0:
		print(i)
		break
	else:
		c += 1
if c == n + 1 - (n // 2 + n % 2):
	print(-1)


(n, m) = list(map(int, input().split()))
k = n // 2 + n % 2
l = n % 2
while k % m != 0 and l <= n:
	k += 1
	l += 2
print(k if k % m == 0 and k <= n else -1)


def doreamon_and_stairs():
	(n, m) = [int(x) for x in input().split(' ', 1)]
	if m > n:
		return -1
	elif m == n:
		return n
	two_steps = n // 2
	single_steps = n % 2
	while (two_steps + single_steps) % m != 0:
		two_steps -= 1
		single_steps += 2
		if two_steps < 0 or single_steps > n:
			return -1
	return two_steps + single_steps
print(doreamon_and_stairs())


(n, m) = map(int, input().split())
a = 0
b = n % 2
n = n - b
for i in range(n // 2, n + 1):
	if a == 0:
		if (i + b) % m == 0:
			print(i + b)
			a = 1
if a == 0:
	print(-1)


import math
(a, b) = input().split()
a = int(a)
b = int(b)
r = 0
z = math.ceil(a / 2)
while r == 0 and z <= a:
	if z % b == 0:
		r = 1
		print(z)
	else:
		z += 1
if r == 0:
	print(-1)


import math as m
(n, p) = map(int, input().split())
ma = n
mi = m.ceil(n / 2)
flag = 0
for i in range(mi, ma + 1):
	if i % p == 0:
		flag = 1
		print(i)
		break
if flag == 0:
	print(-1)


from math import ceil
l = [int(i) for i in input().split(' ')]
n = l[0]
m = l[1]
if n < m:
	print(-1)
elif n == m:
	print(m)
else:
	temp = ceil(n / 2)
	if temp < m:
		print(m)
	elif temp % m == 0:
		print(temp)
	else:
		print(temp + m - temp % m)


(n, m) = map(int, input().split(' '))
if n < m:
	print(-1)
	exit(0)
res = (n + 1) // 2
while res % m != 0:
	res += 1
print(res)


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


(n, m) = map(int, input().split())
from math import ceil
a = ceil(n / 2)
s = 0
for i in range(a, n + 1):
	if i % m == 0:
		print(i)
		s = 1
		break
	else:
		pass
if s == 0:
	print('-1')


(n, m) = [int(x) for x in input().split()]
maxS = n
minS = int(n / 2) if n % 2 == 0 else int(n / 2) + 1

def check(a, b, m):
	for i in range(a, b + 1):
		if i % m == 0:
			return i
	return -1
print(check(minS, maxS, m))


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


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


input_string = input()
(n, m) = input_string.split()
(n, m) = (int(n), int(m))
min_steps = [0]
for i in range(1, 10001):
	min_steps.append(-1)
for i in range(1, 10001):
	max = i
	min = i // 2 + i % 2
	for j in range(min, max + 1):
		if j % m == 0:
			min_steps[i] = j
			break
print(min_steps[n])


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


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


(n, m) = input().split()
n = int(n)
m = int(m)
temp = n // 2 + n % 2
if n < m:
	print(-1)
elif n == m:
	print(n)
elif temp % m == 0:
	print(temp)
else:
	t = 0
	x = n // 2
	for x in range(x, 0, -1):
		f = 2 * x
		s = n - 2 * x
		if (x + s) % m == 0:
			print(x + s)
			x = -1
			break
		else:
			x = x - 1


m = input().split()
n = int(m[0])
m = int(m[1])
k = -1
f = 0
t = 0
if n % 2 == 0:
	f = n // 2
	t = n
else:
	f = max(1, n // 2)
	t = n
for i in range(f, t + 1):
	if i % m == 0 and i * 2 >= n and (i <= n):
		k = i
		break
print(k)


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


s = input()
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
b = []
if a[0] % 2 != 0:
	b.append(1)
for i in range(int(a[0] / 2)):
	b.append(2)
while 2 in b:
	if len(b) % a[1] != 0:
		b.remove(2)
		b.append(1)
		b.append(1)
	else:
		break
if len(b) % a[1] == 0:
	print(len(b))
else:
	print(-1)


(n, m) = map(int, input().strip().split(' '))
x = n // 2
y = n % 2
while x >= 0:
	if (x + y) % m == 0:
		print(x + y)
		exit()
	x -= 1
	y += 2
print(-1)


(n, m) = map(int, input().strip().split())
s = n // 2 + n % 2
if m > n:
	print(-1)
else:
	p1 = s // m * m
	if s - p1 == 0:
		print(p1)
	else:
		print(p1 + m)


(n, m) = [int(i) for i in input().split()]
val = n // 2
if val * 2 != n:
	val += 1
while val <= n:
	if val % m == 0:
		break
	else:
		val += 1
if val <= n:
	print(val)
else:
	print('-1')


(n, m) = list(map(int, input().split()))
if n < m:
	print(-1)
else:
	k = (n + 2 * m - 1) // (2 * m)
	x = n - k * m
	y = 2 * k * m - n
	print(x + y)


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


(n, m) = map(int, input().split())
ans = []
for x in range(1, n):
	if (n - x) % m == 0:
		z = (n - x) / m
		y = n - 2 * x
		if x >= 0 and y >= 0:
			ans.append(x + y)
if len(ans) == 0:
	if n < m:
		print(-1)
	else:
		print(n)
else:
	print(min(ans))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
ans = -1
if n % 2 == 0:
	p = int(n / 2)
else:
	p = int(n / 2) + 1
n += 1
for i in range(p, n):
	if i % m == 0:
		ans = i
		break
	i += 1
if ans == -1:
	print(ans)
else:
	print(ans)


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


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


def count_steps(n, m):
	if n < m:
		return -1
	for i in range(n - m, -1, -1):
		if (n - i) % m == 0 and n - 2 * i >= 0:
			return n - i

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


(n, m) = str(input()).split()
n = int(n)
m = int(m)
lower = int(n / 2) + (n - int(n / 2) * 2)
upper = n
flag = True
for it in range(lower, upper + 1):
	if it % m == 0:
		print(it)
		flag = False
		break
if flag:
	print(-1)


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


(n, m) = map(int, input().split())
ans = n + 1
for i in range(n):
	y = n - (i + 1) * m
	x = (i + 1) * m - y
	if x * y >= 0 and x >= 0:
		ans = min(ans, x + y)
if ans == n + 1:
	print(-1)
else:
	print(ans)


def no_of_moves(n, m):
	x = n // 2
	while x > 0 and (n - x) % m != 0:
		x -= 1
	y = n - 2 * x
	if (n - x) % m == 0:
		return x + y
	else:
		return -1
(n, m) = [int(i) for i in input().split()]
print(no_of_moves(n, m))


def mul(n, y):
	while n > 0:
		n = n - y
	if n == 0:
		return 1
	return 0
(x, y) = map(int, input().split())
if x < y:
	print(-1)
else:
	z = [x // 2 + 1, x // 2][x % 2 == 0]
	while True:
		if mul(z, y):
			print(z)
			break
		else:
			z += 1


(n, m) = [int(i) for i in input().split()]
mul = 0
while True:
	mul += 1
	moves = mul * m
	if n >= moves and n <= moves * 2:
		print(moves)
		break
	elif moves > n:
		print(-1)
		break


(n, s) = input().split()
n = int(n)
s = int(s)
if n % 2 == 0:
	x = int(n / 2)
else:
	x = int(n // 2 + 1)
if s > n:
	print(-1)
else:
	f = 0
	for i in range(x, n + 1):
		if i % s == 0:
			print(i)
			f = 1
			break
	if f == 0:
		print(-1)


(n, m) = map(int, input().split())
flag = False
lists = []
for i in range(int(n / 2)):
	lists.append(2)
s = int(n / 2)
s = s * 2
remaining = n - s
for i in range(remaining):
	lists.append(1)
while lists[0] != 1:
	if int(len(lists) % m) == 0:
		flag = True
		break
	del lists[0]
	lists.append(1)
	lists.append(1)
if len(lists) % m == 0:
	flag = True
if flag == True:
	print(len(lists))
else:
	print('-1')


(n, h) = map(int, input().strip().split())
if n < h:
	print('-1')
else:
	if n % 2 == 0:
		s = n // 2
	else:
		s = n // 2 + 1
	if s % h == 0:
		print(s)
	else:
		print((s // h + 1) * h)


def number():
	test = input().split()
	n = int(test[0])
	m = int(test[1])
	if n < m:
		return -1
	steps = 0
	sum = 0
	while n - sum > m:
		steps = steps + 1
		sum = sum + 2
	steps = steps + (n - sum)
	if steps % m == 0:
		return steps
	floor = steps // m * m
	if floor * 2 >= n:
		return floor
	else:
		return (steps // m + 1) * m
print(str(number()))


nn = list(map(int, input().rstrip().split()))
n = nn[0]
m = nn[1]
flag = 0
minn = float('inf')
for i in range(n + 1):
	if (n - i) // 2 == (n - i) / 2:
		if (n + i) / 2 % m == 0 and (n + i) / 2 < minn:
			flag = 1
			minn = (n + i) / 2
if flag == 1:
	print(int(minn))
else:
	print(-1)


(n, m) = map(int, input().split())
for i in range(n):
	if i * m >= n / 2 and i * m <= n:
		print(i * m)
		raise SystemExit
print(-1)


(n, m) = [int(i) for i in input().split()]
sum = 0
while n != 0:
	if (sum + int(n / 2) + n % 2) % m != 0:
		sum += 1
		n -= 1
	else:
		print(int(sum + n / 2 + n % 2))
		exit(0)
print(-1)


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


import sys
from math import ceil
(n, m) = map(int, input().split())
min_st = int(ceil(n / 2))
max_st = n
for i in range(min_st, max_st + 1):
	if i % m == 0:
		print(i)
		sys.exit()
print('-1')


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


from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

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

def main():
	(n, m) = mi()
	if n < m:
		print('-1')
	elif n == m:
		print(n)
	else:
		ans = n
		for i in range(m, n, m):
			x = 2 * i
			if n <= x:
				print(i)
				break
main()


(n, m) = map(int, input().split())
mx = n
mn = (n - 1) // 2 + 1
max_d = ((mx - 1) // m + 1) * m
min_d = mn // m * m
if max_d - min_d == m and mx != max_d and (mn != min_d):
	print(-1)
else:
	print(((mn - 1) // m + 1) * m)


input = list(map(int, input().split()))
n = input[0]
m = input[1]
sum = 0
if n < m:
	sum = -1
else:
	a = n // 2
	b = n - 2 * a
	sum = a + b
	while sum % m != 0 and a > 0:
		if sum % m == 0:
			break
		else:
			a -= 1
			b += 2
			sum = a + b
print(sum)


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	for i in range(1, 10000):
		if 2 * i * m >= n:
			print(i * m)
			exit(0)


s = str(input()).split()
n = int(s[0])
m = int(s[1])
if n % 2 == 0:
	p = n / 2
else:
	p = n // 2 + 1
while p < n and p % m != 0:
	p += 1
if p % m == 0:
	print(int(p))
else:
	print(-1)


def get(n, m, k):
	return (2 * m * k - n, n - m * k)
(n, m) = [int(__) for __ in input().strip().split()]
for k in range(1, 100001):
	(a, b) = get(n, m, k)
	if a >= 0 and b >= 0 and (a + b > 0) and ((a + b) % m == 0):
		print(a + b)
		exit(0)
print(-1)


(n, m) = map(int, input().split(' '))
chk = 1
if n % 2:
	x = n // 2 + 1
else:
	x = n // 2
i = x // m
mul = m * i
while mul <= n:
	if mul <= n and mul >= x:
		chk = 0
		print(mul)
		break
	i += 1
	mul = m * i
if chk:
	print('-1')


import math
from collections import *
import sys
from functools import reduce

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

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
(n, m) = get_ints()
(l, r) = (n // 2 + (n & 1), n)
val = math.ceil(l / m) * m
print(val if val <= r else -1)


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


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


(n, m) = map(int, input().split())
two_steps = int(n / 2)
res = -1
for i in range(two_steps, -1, -1):
	steps = i + n - 2 * i
	if steps % m == 0:
		res = steps
		break
print(res)


data = input().split()
(N, M) = (int(data[0]), int(data[1]))
divisable_by_M = []
if N == M:
	print(M)
else:
	for i in range(M, N):
		if i % M == 0:
			divisable_by_M.append(i)
	if len(divisable_by_M) == 0:
		print('-1')
	else:
		print(divisable_by_M[len(divisable_by_M) // 2])


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


import math
j = list(map(int, input().split()))
n = j[0]
m = j[1]
ans = 'no'
if n < m:
	print(-1)
else:
	for x in range(math.ceil(n / 2), n + 1):
		if x % m == 0:
			print(x)
			ans = 'yes'
			break
	if ans == 'no':
		print(-1)


def stair():
	if n < m:
		return -1
	if n >= m:
		s = 0
		l = n // 2 * [2]
		if n % 2 == 1:
			if 1:
				l[s] = 1
				s += 1
				l.append(1)
		if 1:
			while len(l) % m != 0:
				l[s] = 1
				s += 1
				l.append(1)
		return len(l)
(n, m) = map(int, input().split())
print(stair())


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


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


import math
(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	x = math.ceil(n / 2)
	y = x / m
	z = m * math.ceil(y)
	print(int(z))


import math
(n, k) = list(map(int, input().split()))
if n < k:
	print(-1)
else:
	moves = math.ceil(math.ceil(n / 2) / k) * k
	print(moves)


(n, m) = map(int, input().split())
(res, ost) = divmod(n, m)
b = 2 - res % 2 if ost != 0 else res % 2
a = (res - b) // 2
print(m * (a + b) if a >= 0 else -1)


(n, s) = map(int, input().split())
min_step = n // 2 + n % 2
max_step = n
get = 0
for i in range(min_step, max_step + 1):
	if i % s == 0:
		print(i)
		get = 1
		break
if get == 0:
	print(-1)


value = 0
min = 0
(max, n) = map(int, input().split())
if n > max:
	print('-1')
else:
	min = int((max + 1) / 2)
	if n < min:
		temp = 1
		value = temp * n
		while value <= max:
			if value >= min:
				break
			temp = temp + 1
			value = temp * n
		print(value)
	else:
		print(n)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
min_steps = (n + 1) // 2
max_steps = n
multiple = min_steps // m * m
next_multiple = multiple + m
if multiple == min_steps:
	print(multiple)
elif next_multiple >= min_steps and next_multiple <= max_steps:
	print(next_multiple)
else:
	print(-1)


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


ID = input().split()
n = int(ID[0])
m = int(ID[1])
l = (n + 1) // 2
r = n
while l % m > 0:
	l += 1
while r % m > 0:
	r -= 1
if l <= r:
	print(l)
else:
	print(-1)


(n, m) = map(int, input().split())
res = -1
two = n // 2
one = n - two * 2
while two >= 0:
	if (two + one) % m == 0:
		res = two + one
		break
	(two, one) = (two - 1, one + 2)
print(res)


(a, n) = list(map(int, input().split()))
k = 0
if a % 2 == 0 and n > 0:
	k = a // 2
	if a // 2 % n == 0:
		print(a // 2)
		quit()
	else:
		while a > 0:
			a = a - 2
			k = k + 1
			if k % n == 0:
				print(k)
				quit()
		print(-1)
		quit()
if n == 0:
	print(-1)
	quit()
else:
	k = a // 2 + 1
	z = a - 1
	if (a // 2 + 1) % n == 0:
		print(a // 2 + 1)
		quit()
	else:
		while z > 0:
			z = z - 2
			k = k + 1
			if k % n == 0:
				print(k)
				quit()
		print(-1)
		quit()


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


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


(n, m) = [int(x) for x in input().split()]
steps = 0
l = n
if n < m:
	print('-1')
	exit()
for i in range(n):
	if l <= 0:
		break
	if l % 2 == 1:
		steps += 1
		l -= 1
	if (steps + l // 2) % m == 0:
		steps += l // 2
		break
	else:
		l -= 2
		steps += 2
if steps % m == 0:
	print(steps)
else:
	print('-1')


def isItPossible(n, p):
	if p > n or p * 2 < n:
		return False
	if n % p == 0 and p * 2 == n:
		return True
	else:
		while p * 2 != n:
			n -= 1
			p -= 1
	if p * 2 == n:
		return True
	else:
		return False
(n, m) = map(int, input().split(' '))
for i in range(1, 10001):
	if isItPossible(n, i * m):
		print(i * m)
		exit()
		break
print('-1')


from sys import *
[n, m] = [int(x) for x in input().split(' ')]
if n < m:
	print('-1')
	exit
else:
	k = n // 2
	l = n - 2 * k
	while k >= 0:
		if (k + l) % m == 0:
			break
		else:
			k -= 1
			l += 2
	print(k + l)


import math
(n, k) = map(int, input().split())
res = []
if n % 2 == 0:
	x = n // 2
	y = n
else:
	x = int(math.ceil(n / 2))
	y = n
c = 0
r = 0
for i in range(x, n + 1):
	if i % k == 0:
		c += 1
		r = i
		break
if c > 0:
	print(r)
else:
	print(-1)


(a, b) = map(int, input().split())
n = a // 2
if a % 2 != 0 and a >= b:
	i = 1
	while True:
		p = n + i
		if p % b == 0:
			print(p)
			break
		else:
			n = n - 1
			i += 2
elif a % 2 == 0 and a >= b:
	i = 0
	while True:
		p = n + i
		if p % b == 0:
			print(p)
			break
		else:
			n = n - 1
			i += 2
else:
	print(-1)


__author__ = 'user'
import io
import math
t = list(map(int, input().split()))
y = t[0]
f = t[1]
max2 = y // 2
min1 = y % 2
while (min1 + max2) % f != 0 and min1 != y:
	max2 -= 1
	min1 += 2
if (min1 + max2) % f == 0:
	print(min1 + max2)
else:
	print(-1)


liste = input().split()
a = int(liste[0])
b = int(liste[1])
petit = int(a / 2) + a % 2
mijouda = True
for i in range(petit, a + 1):
	if i % b == 0:
		print(i)
		mijouda = False
		break
if mijouda:
	print(-1)


from sys import stdin, stdout
nm = list(map(int, stdin.readline().split()))
n = nm[0]
m = nm[1]
x = n // 2
y = 0
output = False
while x >= 0:
	y = n - 2 * x
	if y < 0:
		stdout.write('-1')
		break
	if (x + y) % m == 0:
		steps = x + y
		output = True
		stdout.write(str(steps))
		break
	x -= 1
if not output:
	stdout.write('-1')


import math
(n, m) = [int(x) for x in input().split()]
for i in range(math.ceil(n / 2), n + 1):
	flag = True
	if i % m == 0:
		flag = False
		print(i)
		break
if flag:
	print(-1)


from math import ceil
(n, m) = input().split()
m = int(m)
n = int(n)
x = ceil(n / 2)
if n % 2 == 0:
	count = x
else:
	count = x - 1
if x % m == 0:
	print(x)
else:
	while x % m != 0 and count >= 0:
		x = x - 1
		count = count - 1
		x = x + 2
	if count < 0:
		print('-1')
	else:
		print(x)


def main():
	(n, m) = map(int, input().split())
	if n % 2 == 0:
		l = n // 2
	else:
		l = n // 2 + 1
	for i in range(l, n + 1):
		if i % m == 0:
			print(i)
			return
	print(-1)
main()


def main():
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	res = 0
	if n < m:
		print('-1')
	else:
		if n % 2 != 0:
			n -= 1
			res += 1
		shag_count2 = n / 2
		if (shag_count2 + res) % m == 0:
			print(int(shag_count2 + res))
		else:
			while (shag_count2 + res) % m != 0:
				res += 1
			print(int(shag_count2 + res))
main()


from math import ceil
y = [int(b) for b in input().split()]

def func(y):
	for i in range(ceil(y[0] / 2), y[0] + 1):
		if i % y[1] == 0:
			return i
	return -1
print(func(y))


import sys
(n, m) = map(int, sys.stdin.readline().split())
num_twos = n // 2
num_steps = num_twos + n % 2
num_changed = 0
while num_steps % m != 0 and num_twos > 0 and (num_changed < 30):
	num_twos -= 1
	num_steps += 1
	num_changed += 1
if num_steps % m != 0:
	print(-1)
else:
	print(num_steps)


(n, m) = map(int, input().split())
i = n // 2 + n % 2
ans = 0
while ans == 0 and i <= n:
	if i % m == 0:
		ans = i
	i += 1
if ans == 0:
	ans = -1
print(ans)


import math

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

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
(n, m) = invr()
res = -1
if n % 2 != 0:
	min_move = n // 2 + 1
else:
	min_move = n // 2
max_move = n
for i in range(min_move, max_move + 1):
	if i % m == 0:
		res = i
		break
print(res)


res = 0
(n, m) = [int(x) for x in input().split()]
flag = False
if m > n:
	res = -1
else:
	if n > 0:
		for i in range(n // 2, -1, -1):
			if (n - i) % m == 0:
				res = n - i
				flag = True
				break
	if not flag:
		res = -1
print(res)


(x, y) = map(int, input().split())
d = int((x + (1 - x % 2 == 0)) / 2)
for i in range(0, d + 1 if x % 2 == 0 else d):
	if (d + i) % y == 0:
		print(d + i)
		exit(0)
print('-1')


x = input()
x = x.split(' ')
x = [int(i) for i in x]
if x[0] < x[1]:
	print(-1)
else:
	rem = x[0] % 2
	div = int(x[0] / 2)
	total = div + rem
	while total % x[1] != 0:
		total += 1
	print(total)


(n, m) = map(int, input().split())
if n % 2 == 0:
	mini = n // 2
else:
	mini = n // 2 + 1
resposta = -1
for k in range(mini, n + 1):
	if k % m == 0:
		resposta = k
		break
print(resposta)


str = input().split()
(n, m) = (int(str[0]), int(str[1]))
steps = n // 2 + n % 2
while steps <= n:
	if steps % m == 0:
		print(steps)
		break
	steps += 1
else:
	print(-1)


import os
import sys
from math import ceil
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')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	(n, m) = readints()
	if n < m:
		print(-1)
		return
	start = 1
	while 1:
		check = start * m
		if 2 * check >= n:
			print(check)
			return
		start += 1

def main():
	t = 1
	for _ in range(t):
		solve()
main()


(a, b) = [int(x) for x in input().split(' ')]
d = 0
if b > a:
	print(-1)
else:
	c = int(a / 2) + a % 2
	if c % b != 0:
		d = b - c % b
	print(c + d)


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


inp = input().split()
(n, m) = (int(inp[0]), int(inp[1]))
if n < m:
	print(-1)
else:
	steps = n // 2 + n % 2
	if steps % m == 0:
		print(steps)
	else:
		for i in range(n // 2):
			steps += 1
			if steps % m == 0:
				print(steps)
				break


import sys
import math

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 sinp():
	return sys.stdin.readline().strip()

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

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

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

def p(a):
	print(a)
(n, m) = ninp()
f = 0
tot = 0
if n < m:
	print(-1)
	f = 1
elif n % 2 == 0:
	tot = n // 2
else:
	tot = n // 2 + 1
ans = tot
while tot % m != 0 and f == 0:
	ans += 1
	tot = tot + 1
if f == 0:
	print(ans)


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


(n, k) = map(int, input().split())
from math import ceil
steps = set((i for i in range(ceil(n / 2), n + 1)))
for i in steps:
	if i % k == 0:
		print(i)
		exit()
print(-1)


(n, m) = map(int, input().split())
(res, ans, temp, i) = (0, 0, 0, 0)
if m > n:
	print(-1)
elif m == n:
	print(m)
else:
	res = n // 2 + n % 2
	i = res
	while i <= n:
		if i % m == 0:
			print(i)
			exit()
		i += 1
	print(-1)


num = input().split()
stair_length = int(num[0])
step_mult = int(num[1])
if stair_length < step_mult:
	print('-1')
	exit()
calc = stair_length // 2
if stair_length % 2 != 0:
	calc = calc + 1
while calc % step_mult != 0:
	calc = calc + 1
print(calc)


(n, m) = map(int, input().split())
max_steps = n
min_steps = n % 2 + n // 2
if min_steps % m == 0:
	print(min_steps)
else:
	next_m = min_steps + m - min_steps % m
	if next_m <= max_steps:
		print(next_m)
	else:
		print(-1)


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


(a, b) = map(int, input().split())
if b > a:
	print(-1)
elif a == b:
	print(a)
else:
	ans = []
	for i in range(0, a + 1):
		for j in range(0, a + 1):
			if (i + j) % b == 0 and 2 * i + j == a:
				ans.append(i + j)
	if len(ans) == 0:
		print(-1)
	else:
		print(min(ans))


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


(a, b) = [int(i) for i in input().split()]
import math
num = math.ceil(a / 2)
out = -1
for i in range(num, a + 1):
	if i % b == 0:
		out = i
		break
print(out)


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


raw = input()
raw = raw.split(' ')
raw = [int(x) for x in raw]
n = raw[0]
m = raw[1]
if (n < m) | (m == 0):
	print(-1)
else:
	x = 0
	if n % 2 != 0:
		x = 1
		n = n - 1
	y = n / 2
	a = int(x + y)
	if m > a:
		print(m)
	elif a % m == 0:
		print(a)
	else:
		z = int(a / m) + 1
		a = int(z * m)
		print(a)


(a, b) = map(int, input().split())
c = a
if a < b:
	print('-1')
	exit()
while True:
	if c / 2 % b == 0:
		break
	else:
		c += 1
print(int(c / 2))


q = input().split()
a = int(q[0])
b = int(q[1])
if b > a:
	print(-1)
else:
	x = a // 2 + a % 2
	y = b - x % b
	if x % b == 0:
		print(x)
	else:
		print(x + y)


(n, m) = map(int, input().split())
l = []
for k in range(1, n // 2 + 1):
	x = n - k * m
	y = n - 2 * x
	if x >= 0 and y >= 0 and (x + y > 0):
		l.append(x + y)
if len(l) != 0:
	print(min(l))
else:
	print(-1)


(n, m) = map(int, input().split())
minsteps = 999999
x = 0
if n < m:
	print(-1)
else:
	while 2 * x <= n:
		y = n - 2 * x
		if (x + y) % m == 0:
			minsteps = min(minsteps, x + y)
		x += 1
	print(minsteps if minsteps != 999999 else -1)


(n, m) = map(int, input().split())
r = -1
for i in range(n // 2 + 1):
	if not (n - i) % m:
		r = n - i
print(r)


import sys
(n, m) = map(int, input().split())
x = n // 2 + n % 2
count = x
f = int(0)
if n == m:
	print(n)
	exit(0)
if n == 1 and m != 1:
	print(-1)
	exit(0)
for i in range(x):
	if count % m != 0:
		f = 0
		count += 1
	else:
		f = 1
		break
print(count) if f == 1 else print(-1)


(n, m) = tuple([int(i) for i in input().split(' ')])
maxmimum = n
minimum = n // 2 if n % 2 == 0 else n // 2 + 1
ans = 0
for i in range(minimum, n + 1):
	if i % m == 0:
		ans = i
		break
if ans != 0:
	print(ans)
else:
	print(-1)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from math import ceil, floor, log, sqrt, factorial

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()
x = ceil(n / 2)
flag = 0
for i in range(x, n + 1):
	if i % m == 0:
		ans = i
		flag = 1
		break
if flag == 1:
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split())
if n % 2 == 0:
	a = n // 2
	steps = a
	b = 0
	while steps % m != 0 and b < n:
		b += 2
		steps += 1
		a -= 1
	if steps % m == 0:
		print(steps)
	else:
		print(-1)
else:
	a = n // 2
	steps = a + 1
	b = 1
	while steps % m != 0 and b != n:
		b += 2
		steps += 1
		a -= 1
	if steps % m == 0:
		print(steps)
	else:
		print(-1)


(n, m) = map(int, input().split())
if n % 2 == 1:
	start = n // 2 + 1
else:
	start = n // 2
for steps in range(start, n + 1):
	if steps % m == 0:
		print(steps)
		quit()
print(-1)


line = input().split()
steps = int(line[0])
multiple = int(line[1])
test = 0
twos = int(steps / 2)
ones = steps % 2
minmoves = twos + ones
while twos >= 0:
	if minmoves % multiple == 0:
		print(minmoves)
		test = 1
		break
	else:
		twos = twos - 1
		ones = ones + 2
		minmoves = ones + twos
if test == 0:
	print('-1')


import math
[n, m] = list(map(int, input().split()))
judge = True
for i in range(int(math.ceil(n / 2)), n + 1):
	if i % m == 0:
		print(i)
		judge = False
		break
if judge:
	print(-1)


(n, m) = map(int, input().split())
check = 0
if n < m:
	print(-1)
elif n % 2 == 0:
	check = n // 2
	while check % m != 0:
		check += 1
	print(check)
elif n % 2 != 0:
	check = n // 2 + 1
	while check % m != 0:
		check += 1
	print(check)


z = list(map(int, input().split()))
s = []
c = 0
if z[0] < z[1]:
	print(-1)
elif z[0] == z[1]:
	print(z[0])
else:
	for i in range(z[0]):
		s.append(2)
		c += 2
		if c >= z[0]:
			break
	a = c - z[0]
	if c == z[0] and len(s) % z[1] != 0:
		for i in range(10000000000):
			s.remove(2)
			s.append(1)
			s.append(1)
			if c == z[0] and len(s) % z[1] == 0:
				break
		print(len(s))
	elif c > z[0]:
		for i in range(a):
			s.remove(2)
			s.append(1)
			c -= 1
		if c == z[0] and len(s) % z[1] != 0:
			for i in range(10000000000):
				s.remove(2)
				s.append(1)
				s.append(1)
				if c == z[0] and len(s) % z[1] == 0:
					break
		print(len(s))
	else:
		print(len(s))


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


(s, m) = map(int, input().split())
a = 0
count = 0
while a < s:
	a = s // 2 - count + s % 2 + count * 2
	if a % m == 0:
		print(a)
		exit(0)
	else:
		count += 1
print(-1)


def fun(n, m):
	if n < m:
		return -1
	if n == m:
		return n
	rm = n // m
	li = [m * i for i in range(1, rm + 1)]
	s = 0
	for i in li:
		s = i * 2
		if s >= n:
			break
	return i
(n, m) = list(map(lambda x: int(x), input().split()))
print(fun(n, m))


import math
(N, M) = map(int, input().split())
X = math.ceil(N / 2)
ans = -1
for x in range(X, N + 1):
	if x % M == 0:
		ans = x
		break
print(ans)


(n, m) = map(int, input().split())
moves = 0
i = 1
temp = 0
for i in range(n // 2, -1, -1):
	if temp == 1:
		break
	for j in range(n, 0, -1):
		if i + m * j == n and m * j - i >= 0:
			print(m * j)
			temp = 1
			break
if temp == 0:
	print(-1)


def stairs(n, m):
	if m > n:
		return [-1]
	else:
		(result, a) = (n // 2 + n % 2, list())
		for i in range(1, result + 1):
			if i * m >= result:
				a.append(i * m)
				break
		return a
(N, M) = [int(i) for i in input().split()]
print(*stairs(N, M))


(n, m) = [int(i) for i in input().split()]
low = (n + 1) // 2
ans = (low + m - 1) // m * m
if ans > n:
	ans = -1
print(ans)


from sys import stdin

def main():
	(n, m) = map(int, stdin.readline().strip().split())
	return -1 if n < m else (n - 1) // (2 * m) * m + m
print(main())


w = input().split(' ')
n = int(w[0])
m = int(w[1])
a = 0
b = 0
p = 0
if n < m:
	print('-1')
else:
	for k in range(n):
		a = 2 * k * m - n
		b = n - k * m
		if a >= 0 and b >= 0:
			p = a + b
			break
	print(p)


(n, m) = list(map(int, input().split()))
min_possible = n // 2 + n % 2
b = False
for i in range(10):
	if (min_possible + i) % m == 0 and min_possible + i <= n:
		b = True
		print(min_possible + i)
		break
if not b:
	print(-1)


(n, m) = map(int, input().split())
maxi = n
if n % 2 == 0:
	mini = n // 2
else:
	mini = n // 2 + 1
f = 0
for i in range(mini, maxi + 1):
	if i % m == 0:
		f = 1
		break
if f == 1:
	print(i)
else:
	print('-1')


(n, m) = map(int, input().split())
k = n // (2 * m)
x = n - m * k
y = 2 * m * k - n
if y < 0:
	k += 1
	x = n - m * k
	y = 2 * m * k - n
sol = False
sols = [x + y]
while x >= 0 and y >= 0:
	sol = True
	x = n - m * k
	y = 2 * m * k - n
	sols.append(x + y)
	k += 1
if sol:
	print(min(sols))
else:
	print('-1')


(n, m) = map(int, input().split())
if m > n:
	print(-1)
elif m == n:
	print(n)
else:
	k = n
	ans = 0
	if n % 2 == 0:
		n //= 2
	else:
		n //= 2
		n += 1
	while n != k + 1:
		if n % m == 0:
			print(n)
			break
		else:
			n += 1


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


(n1, m) = map(int, input().split())
n2 = n1
if m > n1:
	print(-1)
else:
	while True:
		if n2 % 2 == 0:
			f1 = int(n2 / 2)
			f2 = n1 - f1 * 2
			if (f1 + f2) % m == 0:
				print(f1 + f2)
				break
		n2 -= 1


from sys import stdin

def main():
	inp = stdin
	(n, m) = map(int, inp.readline().split())
	Min = (n + 1) // 2
	while Min <= n and Min % m != 0:
		Min += 1
	if Min <= n:
		print(Min)
	else:
		print(-1)
main()


line = input()
line = line.split()
n = int(line[0])
m = int(line[1])
if m > n:
	print(-1)
else:
	no2 = n // 2
	no1 = n - 2 * no2
	fixed = no2 // m
	fixed = fixed * m
	no2 = no2 - fixed
	no1 = no1
	total = no1 + no2 * 2
	xtra = total % m
	if total >= m:
		fixed = fixed + m
	elif total == 0:
		fixed = fixed
	elif fixed > 0:
		fixed = fixed + m
	print(fixed)


from math import ceil
(n, m) = map(int, input().split())
(M, mi) = (n, ceil(n / 2))
ans = -1
flag = False
for i in range(mi, M + 1):
	if i % m == 0:
		flag = True
		ans = i
		break
if flag:
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split())
count = 0
counter2 = 0
nn = n
while n - 2 >= 0:
	n -= 2
	counter2 += 1
else:
	if n > 0:
		n -= 1
		count += 1
count += counter2
check = 1
while check == 1:
	if counter2 > 0 and count % m != 0:
		counter2 -= 1
		count += 1
	if count % m == 0:
		break
	if count % m != 0 and counter2 == 0:
		check = -1
if check == 1:
	print(count)
else:
	print(-1)


(a, b) = map(int, input().split())
if a % 2 == 0:
	l = list(range(a // 2, a + 1))
else:
	l = list(range(a // 2 + 1, a + 1))
s = 0
for i in l:
	if i % b == 0:
		print(i)
		break
	s += 1
if s == len(l):
	print(-1)


import math
s = input().split()
n = int(s[0])
m = int(s[1])
min = n // 2 + n % 2
max = n
ans = math.ceil(min / m) * m
if ans <= max:
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split())
k = True
if n < m:
	print(-1)
else:
	for i in range(round(n / 2 + 0.3), n + 1):
		if i % m == 0 and k == True:
			print(i)
			k = False


(s, t) = input().split()
n = int(s)
m = int(t)
if n % 2 == 0:
	min = int(n / 2)
else:
	min = int(n / 2) + 1
i = min
p = 0
step = 0
while i <= n:
	if min % m == 0:
		step = min
		p = 1
		break
	else:
		min += 1
		p = 0
	i += 1
if p == 1:
	print(int(step))
else:
	print('-1')


(a, b) = map(int, input().split())
mx = a + 1
k = a % 2
k1 = a / 2 % b
if k == 0:
	m = a // 2
	m -= 1
else:
	m = a // 2 + 1
	m -= 1
a = m
if k == 0 and k1 == 0:
	l = (mx - 1) / 2
else:
	while k1 != 0:
		a = a + 1
		k1 = a % b
		l = a
		if l >= mx:
			l = -1
			k1 = 0
print(int(l))


a = [int(x) for x in input().split()]
if a[0] >= a[1]:
	b = []
	for i in range(0, a[0] + 1, 2):
		n = a[0] - i
		n = n + i // 2
		b.append(n)
	b = b[::-1]
	for i in range(len(b)):
		if b[i] % a[1] == 0:
			print(b[i])
			break
else:
	print(-1)


def main():
	(steps, multiple) = [int(x) for x in input().split()]
	ones = steps % 2
	minimum_steps = steps // 2 + ones
	while minimum_steps % multiple != 0:
		minimum_steps += 1
	if minimum_steps % multiple == 0 and minimum_steps != multiple:
		print(minimum_steps)
	elif steps == multiple:
		print(minimum_steps)
	elif minimum_steps == multiple:
		if steps > multiple:
			print(minimum_steps)
		else:
			print('-1')
main()


import math
(n, k) = map(int, input().split())
if n % 2 == 0:
	steps = n // 2
else:
	steps = n // 2 + 1
result = -1
while steps % k != 0 and steps <= n:
	steps += 1
if steps > n:
	steps -= 1
if steps % k == 0:
	result = steps
print(result)


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


from math import ceil
(n, m) = map(int, input().split())
minmoves = 0
maxmoves = 0
if n % 2 == 0:
	minmoves = n // 2
	maxmoves = n
else:
	minmoves = n // 2 + 1
	maxmoves = n
if maxmoves // m > minmoves // m or minmoves // m == minmoves / m:
	if minmoves % m == 0:
		print(minmoves)
	else:
		print(minmoves + m - minmoves % m)
else:
	print(-1)


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


import math
(a, b) = map(int, input().split())
f = 0
j = math.ceil(a / 2)
for i in range(j, a + 1):
	if i % b == 0:
		print(i)
		f = 1
		break
if f == 0:
	print(-1)


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

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

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

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

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
import math
(n, m) = get_ints()
for i in range((n + 1) // 2, n + 1):
	if i % m == 0:
		print(i)
		break
else:
	print(-1)


Datos = input('')
Datos = Datos.split()
N = int(Datos[0])
M = int(Datos[1])
if M >= N:
	if M == N:
		print(N)
	else:
		print(-1)
elif N % 2 == 0:
	Movi = N // 2
	Ayuda = 0
	while Ayuda == 0:
		if Movi % M == 0:
			Ayuda = 1
			print(Movi)
		else:
			Movi = Movi + 1
else:
	Movi = N // 2 + 1
	Ayuda = 0
	while Ayuda == 0:
		if Movi % M == 0:
			Ayuda = 1
			print(Movi)
		else:
			Movi = Movi + 1


(n, m) = [int(s) for s in input().split()]
count = 0
if m > n:
	print('-1')
else:
	while n - 2 > -1:
		n -= 2
		count += 1
	count += n
	while count % m != 0:
		count -= 1
		count += 2
	print(count)


l = input().split(' ')
n = int(l[0])
m = int(l[1])
if m > n:
	print('-1')
else:
	min = int(n / 2) if n % 2 == 0 else int(n / 2) + 1
	if min % m == 0:
		print(str(min))
	else:
		min += m - min % m
		print(str(min))


(x, y) = input().split()
x = int(x)
y = int(y)
if x < y:
	print(-1)
else:
	if x % 2 != 0:
		x += 1
	z = x // 2
	while z % y != 0:
		z += 1
	print(z)


(n, m) = map(int, input().split())
val = [n // 2 + (n & 1) + m - (n // 2 + (n & 1)) % m, n // 2 + (n & 1)][(n // 2 + (n & 1)) % m == 0]
print([val, -1][val > n])


(n, m) = list(map(int, input().split()))
x = []
for j in range(0, n + 1):
	if (n + j) / 2 % m == 0:
		x.append((n - j) // 2 + j)
if len(x) == 0:
	print('-1')
else:
	print(min(x))


import array
arr1 = array.array('l', [])
arr2 = array.array('l', [])
arr2 = [int(i) for i in input().split()]
n = arr2[0]
m = arr2[1]
if n % 2 == 0:
	a = int(n / 2)
	b = n
else:
	a = int(n / 2 + 1)
	b = n
c = b - a
aa = a
dd = 0
ck = 0
for i in range(0, c + 1, 1):
	if aa % m == 0:
		dd = aa
		ck = 1
	if aa % m == 0:
		break
	aa = aa + 1
if ck == 1:
	print(dd)
else:
	print('-1')


def main():
	(n, m) = map(int, input().split(' '))
	mi = int(100000000.0)
	for x in range(100000):
		y = (n - x) // 2
		if y >= 0 and x + 2 * y == n and ((x + y) % m == 0):
			mi = min(mi, x + y)
	if mi == int(100000000.0):
		return -1
	return mi
print(main())


(n, m) = map(int, input().split())
if n == 1 and m > n:
	print('-1')
	exit()
if n % 2 != 0:
	n += 1
x = n / 2
while x <= n:
	if x % m == 0:
		print(int(x))
		exit()
	x += 1
print('-1')


(n, m) = map(int, input().split())
count1 = 0
count2 = 0
if m > n:
	print('-1')
else:
	while n > 0:
		if n % 2 == 1:
			n -= 1
			count1 += 1
		else:
			n -= 2
			count2 += 1
	while (count1 + count2) % m != 0:
		count2 -= 1
		count1 += 2
	print(count1 + count2)


def check(x, y):
	if x < y:
		return -1
	else:
		if x % 2 == 0:
			x = x // 2
		else:
			x = x // 2 + 1
		while x % y != 0:
			x += 1
		return x
(x, y) = [int(i) for i in input().split()]
print(check(x, y))


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


a = input().split()
n = int(a[0])
m = int(a[1])
if n // m < 1:
	print(-1)
else:
	optAmount = int(n / 2) + n % 2
	while not optAmount % m == 0:
		optAmount += 1
	if optAmount > n:
		print(-1)
	else:
		print(optAmount)


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

def fi():
	return float(input())

def si():
	return input()

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

def li():
	return list(mi())
import math
(n, m) = mi()
a = math.ceil(n / 2)
b = n // 1
if max(a, b) // m == 0:
	print(-1)
	exit()
elif n == m:
	print(n)
else:
	for i in range(a, b):
		if not i % m:
			ans = i
			break
	print(ans)


(n, m) = map(int, input().split())
r = n % 2
q = n // 2
s = True
for i in range(r, n + 1, 2):
	k = i + int((n - i) / 2)
	if k % m == 0:
		print(k)
		s = False
		break
if s:
	print(-1)


inp = input().split()
n = int(inp[0])
div = int(inp[1])
if n % 2 == 0:
	div2 = n // 2
else:
	div2 = n // 2 + 1
c = 0
for i in range(div2, n + 1):
	if i % div == 0:
		print(i)
		c = 1
		break
if c == 0:
	print(-1)


(n, m) = map(int, input().split())
i = m
while 2 * i < n:
	i += m
y = n - i
x = i - y
if x < 0 or y < 0:
	print(-1)
else:
	print(x + y)


(a, b) = map(int, input().split())
sum = 0
for i in range(b, a + 1, b):
	if i <= a and 2 * i >= a:
		sum = i
		break
if a >= b:
	print(sum)
else:
	print(-1)


import math
(n, m) = [int(inp) for inp in input().strip().split()]
final_total_steps = -1
for i in range(int(math.floor(n / 2)), -1, -1):
	b = i
	b_steps = b * 2
	a_steps = n - b_steps
	a = a_steps
	total_steps = a + b
	if total_steps % m == 0:
		final_total_steps = total_steps
		break
print(final_total_steps)


import math
inp = input().split()
n = int(inp[0])
m = int(inp[1])
if n < m:
	print(str(-1))
else:
	twos = math.floor(n / 2)
	ones = n - 2 * n
	mul = m * math.ceil(n / (2 * m))
	print(int(mul))


from math import ceil
(n, m) = map(int, input().split())
mx = n
mn = (n + 1) // 2
x = int(ceil(mn / m)) * m
res = x if x <= mx else -1
print(res)


from math import ceil
(steps, m) = map(int, input().split())
toPrint = -1
for i in range(ceil(steps / 2), steps + 1):
	if i % m == 0:
		toPrint = i
		break
print(toPrint)


(n, m) = map(int, input().split())
t = (n + 1) // 2
s = (t - 1) // m * m + m
print([s, -1][s > n])


import math
(n, m) = map(int, input().split())
t = math.ceil(n / 2)
f = 0
while t <= n:
	if t % m == 0:
		print(math.floor(t))
		f = 1
		break
	t += 1
if not f:
	print(-1)


s = input().split(' ')
n = int(s[0])
m = int(s[1])
f = 0
if n & 1:
	l = n / 2
	l += 1
	f = 1
else:
	l = n / 2
	f = 2
r = 0
l = int(l)
if l % m == 0:
	print(l)
else:
	while True:
		if l % m == 0:
			print(l)
			break
		if l == n:
			if n % m == 0:
				print(n)
				break
			else:
				print('-1')
				break
		else:
			l += 1


f = input().split()
n = int(f[0])
m = int(f[1])
O = int(0)
l = int(0)
if n % 2 == 0:
	l = n // 2
else:
	l = n // 2 + 1
for i in range(l, n + 1):
	if i % m == 0:
		print(i)
		O += 1
		break
if O == 0:
	print(-1)


(n, m) = map(int, input().split())
moves = []
for i in range(0, n + 1, 2):
	if (i / 2 + n - i) % m == 0:
		moves.append(int(i / 2 + n - i))
try:
	print(min(moves))
except:
	print(-1)


isDebug = False
(n, m) = [int(x) for x in input().split()]
r = int(n % 2)
t = int(n / 2)
print(f'n={n}, m={m}, t={t}') if isDebug else ''
found = False
a = t
b = r
for i in range(0, t + 1):
	print(f'---\ni={i}, a={a}, b={b}') if isDebug else ''
	if (a + b) % m == 0:
		found = True
		break
	a = a - 1
	b = b + 2
print(f"{(a + b if found else '-1')}")


(n, m) = map(int, input().strip().split(' '))
q = n // 2
r = n % 2
a = q + r
if a % m == 0:
	print(a)
else:
	k = 0
	while a <= n and n >= m:
		a = a + 1
		if a % m == 0:
			print(a)
			k = 1
			break
	if k == 0:
		print(-1)


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


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


import sys
import math
(n, m) = [int(x) for x in sys.stdin.readline().split()]
k = int(n / 2)
if n % 2 != 0:
	k += 1
for i in range(k, n + 1):
	if i % m == 0:
		print(i)
		exit()
print(-1)


a = list(map(int, input().split()))
n = int(a[0])
m = int(a[1])
p = int(n / 2)
if n < m:
	print(-1)
else:
	q = n % 2
	r = p + q
	s = r % m
	if s == 0:
		m = 0
	print(r + (m - s))


(a, b) = [int(i) for i in input().split()]
if b > a:
	print(-1)
else:
	if a % b == 0:
		x = a // 2
	else:
		x = a // 2 + 1
	for j in range(x, x + 11):
		if j % b == 0:
			print(j)
			break


(x, y) = map(int, input().split())
if x < y:
	z = -1
else:
	z = (x + 2 * y - 1) // 2 // y * y
print(z)


s = input().split()
n = int(s[0])
m = int(s[1])
count = 0
start = int(n / 2)
found = 0
for i in range(start, -1, -1):
	j = n - i * 2
	if (i + j) % m == 0:
		print(i + j)
		found = 1
		break
if found == 0:
	print(-1)


from math import ceil
a = list(map(int, input().split()))
if a[0] < a[1]:
	print(-1)
else:
	x = ceil(a[0] / 2)
	while x % a[1] != 0:
		x += 1
	print(x)


line = input().split(' ')
n = int(line[0])
m = int(line[1])
a = list(range((n + 1) // 2, n + 1))
a = [x for x in a if x % m == 0]
if len(a) == 0:
	print(-1)
else:
	print(a[0])


(s, dv) = map(int, input().split())
x = s // 2 + 1
move = True
if s % 2 == 0:
	x = s // 2
if s < dv:
	print(-1)
else:
	while move and x <= s:
		if x % dv != 0:
			x += 1
		elif x % dv == 0:
			move = False
	print(x)


class CodeforcesTask476ASolution:

	def __init__(self):
		self.result = ''
		self.n_m = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]

	def process_task(self):
		sols = []
		for m in range(1, self.n_m[0] // self.n_m[1] + 1):
			a = self.n_m[0] - m * self.n_m[1]
			b = self.n_m[1] * m - a
			if a >= 0 and b >= 0:
				if 2 * a + b == self.n_m[0]:
					sols.append(a + b)
		if sols:
			self.result = str(min(sols))
		else:
			self.result = '-1'

	def get_result(self):
		return self.result
Solution = CodeforcesTask476ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


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


def stairs(n, m):
	arr = list()
	for i in range(n):
		if 2 * i <= n and (n - i) % m == 0:
			arr.append(i)
	if arr:
		steps_2 = max(arr)
		steps_1 = n - 2 * steps_2
		total_steps = steps_2 + steps_1
		print(total_steps)
	else:
		print(-1)
(n, m) = input().split()
stairs(int(n), int(m))


def test96():
	(sum_step, base) = map(int, input().strip().split(' '))
	for x in range(base, sum_step + 1, base):
		if x <= sum_step <= x * 2:
			print(x)
			return
	print(-1)
test96()


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


(n, m) = map(int, input().split())
tmp = m
while not (n - 1) // 2 + 1 <= tmp <= n:
	if tmp > n:
		print(-1)
		exit(0)
	tmp += m
print(tmp)


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


import sys
inp = sys.stdin.read().strip().split(' ')
n = int(inp[0])
m = int(inp[1])
if n % 2 == 0:
	s = n // 2
	add = 0
else:
	s = n // 2
	add = 1
modu = (s + add) % m
if s < m - modu and modu > 0:
	print(-1)
else:
	print(s + add - modu + m if modu != 0 else s + add)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
import heapq
infinite = float('inf')
(n, m) = RI()
k = 1
mini = 1000000000
while 1:
	x = n - m * k
	y = 2 * m * k - n
	if x >= 0 and y >= 0:
		mini = min(x + y, mini)
	if x < 0:
		break
	k += 1
if mini == 1000000000:
	print(-1)
else:
	print(mini)


(a, b) = map(int, input().split())
(c, d) = ([], [1, 1])
if a % 2 == 0:
	while a >= 2:
		c.append(2)
		a -= 2
elif a % 2 != 0:
	while a >= 2:
		c.append(2)
		a -= 2
	c.append(1)
for x in range(0, len(c) + 2):
	if len(c) % b == 0:
		print(len(c))
		quit()
	elif 2 not in c:
		print(-1)
		quit()
	elif len(c) % b != 0:
		c.remove(2)
		c += d
	else:
		print(-1)
		quit()


import math, os, sys
import string, re
import itertools, functools, operator
from collections import Counter

def inputint():
	return int(input())

def inputarray(func=int):
	return map(func, input().split())
(n, m) = inputarray()
for i in range(n // 2, -1, -1):
	if (n - i) % m == 0:
		print(n - i)
		quit()
print(-1)


import math
string = input()
numbers = string.split(' ')
m = int(numbers[0])
n = int(numbers[1])
results = -1
for x in range(math.ceil(m / 2), m + 1):
	if x % n == 0:
		results = x
		break
print(results)


(n, m) = map(int, input().split())
steps = (n + 1) // 2
while steps % m:
	steps += 1
print([steps, -1][n < m])


x = list(map(int, input().split()))
p = x[0] // 2
if x[0] % 2 != 0:
	p += 1
if x[0] >= x[1]:
	while p % x[1] != 0:
		p += 1
	print(p)
if x[0] < x[1]:
	print('-1')


import math

def main():
	(n, m) = map(int, input().split())
	d = n // 2 + n % 2
	f = -1
	for i in range(d, n + 1):
		if i % m == 0:
			f = i
			break
	print(f)
main()


(m, n) = [int(i) for i in input().split()]
c = (m + 1) // 2
k = 0 if c % n == 0 else n - c % n
if k == 0 or c // n < m // n:
	print(c + k)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
steps = n // 2 + n % 2
for x in range(n // 2):
	if steps % k == 0:
		break
	else:
		steps += 1
print(steps) if steps % k == 0 else print(-1)


(x, y) = map(int, input().split())
if x < y:
	print(-1)
else:
	c = x / 2 % y
	if c != 0:
		c = y - int(c)
	print(int(x // 2 + c))


(n, m) = map(int, input().split())
two = n // 2
one = 0
if two * 2 == n:
	one = 0
else:
	one = n - two * 2
if (one + two) % m == 0:
	print(one + two)
else:
	while (one + two) % m != 0:
		two = two - 1
		one = one + 2
		sum = two + one
		if two < 0:
			sum = -1
			break
	print(sum)


n = [int(x) for x in input().split()]
st = n[0]
ml = n[1]
counter = 0
if st % 2 == 0:
	counter = st // 2
else:
	counter = st // 2 + 1
for i in range(st):
	if ml > st:
		print(-1)
		break
	elif counter % ml == 0:
		print(counter)
		break
	else:
		counter += 1


s = [int(n) for n in input().split()]
if s[0] >= s[1]:
	j = s[0] // 2 + s[0] % 2
	if j % s[1] == 0:
		print(j)
	else:
		k = (j // s[1] + 1) * s[1]
		print(k)
else:
	print(-1)


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


(steps, goon) = input().split(' ')
steps = int(steps)
goon = int(goon)
counter = 0
if steps >= goon:
	while True:
		if steps > 1:
			steps -= 2
			counter += 1
		elif steps == 1:
			steps -= 1
			counter += 1
		if steps == 0:
			break
	while counter % goon != 0:
		counter += 1
	print(counter)
else:
	print(-1)


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


S = input().split()
n = int(S[0])
m = int(S[1])
if n % 2 == 0:
	k = n // 2
else:
	k = n // 2 + 1
while k % m != 0 and k < n:
	k = k + 1
if m > n:
	print(-1)
else:
	print(k)


(n, m) = map(int, input().split())
if n < m:
	print(-1)
	quit()
t = n // 2 + n % 2
while t % m != 0 and t < n:
	t += 1
print(t)


import sys
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
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

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)]
t = 1
for _ in range(t):
	(n, m) = l()
	n += 1
	ans = -1
	for i in range(n // 2, n):
		if i % m == 0:
			ans = i
			break
	print(ans)


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


def get_result():
	(n, m) = [int(val) for val in input().split()]
	if m > n:
		return -1
	initial = n // 2 + n % 2
	if initial % m == 0:
		return initial
	for i in range(initial):
		initial += 1
		if initial % m == 0:
			return initial
	return -1
print(get_result())


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


a = [int(i) for i in input().split()]
n = a[0]
m = a[1]
ans = None
if n >= m:
	if n % 2 == 0:
		b = n / 2
		for i in range(10):
			if (b + i) % m == 0:
				ans = b + i
				break
	elif n % 2 == 1:
		b = n // 2 + 1
		for i in range(10):
			if (b + i) % m == 0:
				ans = b + i
				break
	if ans == None:
		print(-1)
	else:
		print(int(ans))
else:
	print(-1)


(n, m) = map(int, input().strip().split(' '))
min_steps = n // 2 + n % 2
while min_steps <= n:
	if min_steps % m == 0:
		break
	min_steps += 1
if min_steps > n:
	print('-1')
else:
	print(min_steps)


(n, m) = list(map(int, input().split()))
min_step = 0
max_step = n
if n % 2 == 1:
	min_step = int((n + 1) / 2)
else:
	min_step = int(n / 2)
if min_step % m == 0:
	print(min_step)
else:
	t = int(min_step / m)
	if (t + 1) * m <= max_step:
		print(int((t + 1) * m))
	else:
		print(-1)


(n, k) = map(int, input().split())
b = n % 2
a = n
n = n // 2 + b
while n % k != 0:
	n += 1
	if n > a:
		print(-1)
		exit()
print(n)


(a, b) = map(int, input().split())
from math import ceil as f
if a < b:
	print(-1)
else:
	s = a // 2
	print(f((a // 2 + a % 2) / b) * b)


(m, n) = map(int, input().split())
nums = []
final = []
for i in range(m):
	k = (m - i) // 2
	p = 2 * k
	nums.append(k + (m - p))
for j in range(len(nums)):
	if nums[j] % n == 0:
		final.append(nums[j])
if len(final) == 0:
	print('-1')
else:
	print(min(final))


(n, m) = map(int, input().split())
res = -1
cur = n // 2 + n % 2
while cur <= n:
	if cur % m == 0:
		res = cur
		break
	cur += 1
print(res)


(n, k) = tuple(map(int, input().split()))
if n < k:
	print(-1)
else:
	ans = n // 2
	m = n % 2
	ans += m
	if ans % k == 0:
		print(ans)
	else:
		while ans % k != 0 and ans <= n:
			ans += 1
		print(ans)


(n, m) = list(map(int, input().split()))
(i, min) = (n, -1)
while i >= m:
	if not i % m and i * 2 >= n:
		min = i
	i -= 1
print((min, '-1')[min == 0])


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


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


(x, y) = map(int, input().split())
print([((x + 1) // 2 + y - 1) // y * y, '-1'][x < y])


(n, m) = map(int, input().split())
if n < m:
	print(-1)
else:
	rem = n % 2
	ans = int((n - rem) / 2 + rem)
	if ans % m == 0:
		print(ans)
	else:
		while ans % m != 0 and ans < n:
			ans += 1
		print(ans)


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
(n, m) = R()
for k in range(n // m + 1):
	x = 2 * k * m - n
	y = n - k * m
	if x >= 0 and y >= 0:
		print(x + y)
		exit()
print('-1')


line = input().split(' ')
N = int(line[0])
M = int(line[1])

def get_min_number_of_steps(N):
	if N % 2 == 0:
		return [0, N // 2]
	else:
		return [1, N // 2]
oneStairSteps = get_min_number_of_steps(N)[0]
twoStairSteps = get_min_number_of_steps(N)[1]
while (oneStairSteps + twoStairSteps) % M != 0 and twoStairSteps > 0:
	oneStairSteps += 2
	twoStairSteps -= 1
if (oneStairSteps + twoStairSteps) % M == 0:
	print(oneStairSteps + twoStairSteps)
else:
	print(-1)


x = []
x = input().split()
sum = 0
s = int(x[0]) // 2
m = int(x[0]) % 2
while s >= 0:
	sum = s + m
	if sum % int(x[1]) == 0:
		print(sum)
		break
	s -= 1
	m += 2
else:
	print(-1)


(n, m) = map(int, input().split())
if n % 2 == 0:
	k = n // 2
else:
	k = n // 2 + 1
count = 0
while k != n + 1:
	if k % m == 0:
		print(k)
		count += 1
		break
	k += 1
if count == 0:
	print(-1)


from math import ceil
I = lambda : map(int, input().split())
(n, m) = I()
if m > n:
	print(-1)
	exit()
if m == n:
	print(m)
	exit()
Move = range(ceil(n / 2), n + 1)
for i in Move:
	if i % m == 0:
		print(i)
		exit()
print(-1)


s = input().split()
n = int(s[0])
m = int(s[1])
if n < m:
	print(-1)
	exit()
min = n // 2 + n % 2
if min % m == 0:
	print(min)
else:
	print((min // m + 1) * m)


from math import ceil
(n, m) = [int(i) for i in input().split()]
if n < m:
	print(-1)
else:
	ans = ceil(n / 2)
	while ans % m != 0:
		ans += 1
	print(ans)


import math

def solve(n, k):
	result = math.inf
	not_found = True
	p = n // 2
	while p >= 0:
		s = p + (n - 2 * p)
		if s % k == 0:
			result = min(result, s)
			not_found = False
		p -= 1
	if not_found:
		return -1
	else:
		return result
(n, k) = list(map(int, input().strip().split()))
result = solve(n, k)
print(result)


(n, m) = map(int, input().split())
import math
i = math.ceil(math.ceil(n / 2) / m)
if i >= 1 and i * m <= n:
	print(i * m)
else:
	print(-1)


import math
(schodov, delitel) = map(int, input().split())
krokov = math.ceil(math.ceil(schodov / 2) / delitel) * delitel
if krokov > schodov:
	print(-1)
else:
	print(krokov)


from sys import stdin, stdout
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')

def solve():
	(n, m) = mp()
	a = n >> 1
	c = 0
	b = n % 2
	for i in range(a + 1):
		if (a + b) % m == 0:
			pr(a + b)
			return
		a -= 1
		b += 2
	pr(-1)
for _ in range(1):
	solve()


arr = list(map(int, input().split()))
count = 0
sum = 0
if arr[0] % 2 == 0:
	sum = arr[0] / 2
else:
	sum = arr[0] / 2 + 1
for i in range(int(sum), arr[0] + 1):
	if i % arr[1] == 0:
		print(i)
		count = 1
		break
if count == 0:
	print(-1)


def min_steps(n, m):
	turns = m
	if n < m:
		return -1
	while True:
		max_steps = turns * 2
		if max_steps >= n:
			num_changes = max_steps - n
			if 2 * turns - num_changes == n:
				return turns
		turns += m
		if turns > n:
			return -1
(n, m) = list(map(int, input().split()))
num_steps = min_steps(n, m)
print(num_steps)


(a, b) = map(int, input().split(' '))
i = 0
c = 0
if a < b:
	c = 0
else:
	j = a / 2
	k = a % 2
	j = int(j) + int(k)
	l = j
	while j <= a:
		if l % b == 0 and i <= j:
			print(l)
			c = 1
			break
		else:
			c = 0
		i += 1
		l = j + i
if c == 0:
	print('-1')


import math
(n, m) = list(map(int, input().split()))
res = 0
if n == 0:
	print(0)
	quit()
if m > n:
	print(-1)
	quit()
for i in range((n + 1) // 2, n + 1):
	if i % m == 0:
		print(i)
		quit()


(n, m) = [int(y) for y in input().split()]
if n < m:
	print(-1)
elif n % 2 == 0:
	k = n // 2
	while k % m != 0:
		k += 1
	print(k)
elif n % 2 != 0:
	k = n // 2 + 1
	while k % m != 0:
		k += 1
	print(k)


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


(steps, multiple) = [int(a) for a in input().split()]
if multiple > steps:
	print(-1)
elif multiple == steps:
	print(steps)
else:
	moves = steps // 2 + steps % 2
	if moves % multiple > multiple:
		print(-1)
	else:
		while moves % multiple != 0:
			moves += 1
		print(moves)


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


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')
di8 = ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
di4 = ((1, 0), (0, 1), (-1, 0), (0, -1))

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)

def binary(n):
	return bin(n)[2:]

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

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

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

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 seive(n):
	a = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	prime[0] = prime[1] = False
	return (a, prime)

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

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

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

def IF(c, t, f):
	return t if c else f

def YES(c):
	print(IF(c, 'YES', 'NO'))

def Yes(c):
	print(IF(c, 'Yes', 'No'))

def yes(c):
	print(IF(c, 'yes', 'no'))

def JA(a, sep=' '):
	print(sep.join(map(str, a)))

def JAA(a, s='\n', t=' '):
	return s.join((t.join(map(str, b)) for b in a))

def PS(a, s=' '):
	print(str(a), end=s)

def I():
	return int(inp())

def F():
	return float(inp())

def LI():
	return list(map(int, inp().split()))

def LF():
	return list(map(float, inp().split()))

def MATI(n):
	return [LI() for i in range(n)]

def MATS(n):
	return [list(inp()) for i in range(n)]

def IV():
	return map(int, inp().split())

def FV():
	return map(float, inp().split())

def LS():
	return list(inp())

def S():
	return inp()
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))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 0

def solve():
	(n, m) = IV()
	if m > n:
		print(-1)
		return
	if m == n:
		print(n)
		return
	one = n % 2
	two = n // 2
	x = one + two
	p = -x % m
	if not x % m:
		print(x)
		return
	x += p
	if x > n:
		print(-1)
	else:
		print(x)

def main():
	flag = 1
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 0
	t = 1
	if TestCases:
		t = I()
	for _ in range(1, t + 1):
		solve()
	if flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


(a, c) = map(int, input().split())
was = False
for b in range(0, a + 1, c):
	if a - b >= 0 and 2 * b - a >= 0:
		print(b)
		was = True
		break
if not was:
	print(-1)


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


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


(n, k) = map(int, input().split())
steps = n // 2
step = steps + 1 if n % 2 else steps
rang = [step, step + steps]
for i in range(rang[0], rang[1] + 1):
	if i % k == 0:
		print(i)
		quit()
print(-1)