#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int singl = n % 2;
  int doubl = n / 2;
  for (; doubl >= 0; doubl--, singl = singl + 2) {
    int total = singl + doubl;
    if (total % m == 0) {
      printf("%d", total);
      return 0;
    }
  }
  printf("%d", -1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11b9 <main+0x99>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    119d <main+0x7d>
mov    -0x18(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ca <main+0xaa>
jmp    11a2 <main+0x82>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    115f <main+0x3f>
lea    0xe43(%rip),%rdi
mov    $0xffffffff,%esi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%ecx
mov    $0xffffffff,%esi
cmp    $0xffffffff,%ecx
jl     1176 <main+0x56>
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
mov    %edi,%eax
and    $0xfffffffe,%eax
sub    %eax,%ecx
sar    %edi
mov    (%rsp),%r8d
add    %edi,%ecx
add    $0x1,%edi
nopl   0x0(%rax)
mov    %ecx,%eax
cltd
idiv   %r8d
test   %edx,%edx
je     1174 <main+0x54>
add    $0x1,%ecx
add    $0xffffffff,%edi
jg     1160 <main+0x40>
jmp    1176 <main+0x56>
mov    %ecx,%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%8 = load i32, i32* %2
%9 = srem i32 %8, 2
store i32 %9, i32* %4
%10 = load i32, i32* %2
%11 = sdiv i32 %10, 2
store i32 %11, i32* %5
br label %12
12: ; preds = %27, %0
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* %3
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 0, i32* %1
br label %34
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 2
store i32 %31, i32* %4
br label %12
32: ; preds = %12
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %34
34: ; preds = %32, %23
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, -2
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = sdiv i32 %6, 2
%10 = srem i32 %6, 2
%11 = load i32, i32* %2
br label %12
12: ; preds = %8, %18
%13 = phi i32 [ %9, %8 ], [ %19, %18 ]
%14 = phi i32 [ %10, %8 ], [ %20, %18 ]
%15 = add nsw i32 %13, %14
%16 = srem i32 %15, %11
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = add nsw i32 %13, -1
%20 = add nsw i32 %14, 2
%21 = icmp sgt i32 %13, 0
br i1 %21, label %12, label %22
22: ; preds = %18, %12, %0
%23 = phi i32 [ -1, %0 ], [ %15, %12 ], [ -1, %18 ]
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
ret i32 0
}