99 100 100 100 100
 57 83 11 4 93
 99 99 99 99 99
 100 0 0 0 0
 0 1 2 3 4
 93 100 99 90 98
 87 38 19 33 100
 1 1 1 1 1
 0 0 0 0 1
 2 3 4 5 6
 1 2 1 2 3
 0 0 0 0 0
 100 100 100 100 100
 43 83 1 0 23
 43 83 1 100 23
 56 0 0 0 4
 99 98 98 99 100

-1
 -1
 99
 20
 2
 96
 -1
 1
 -1
 4
 -1
 -1
 100
 30
 50
 12
 -1

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)

