#include <bits/stdc++.h>
int main(void) {
  int n, m, a;
  scanf("%d %d", &n, &m);
  a = n / 2;
  if (m > n)
    printf("-1\n");
  else {
    if (n % 2 != 0) a = a + 1;
    while (1) {
      if (a % m == 0) {
        printf("%d\n", a);
        break;
      }
      a++;
    }
  }
  return 0;
}
