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