#include <bits/stdc++.h>
int n, m;
int min, max;
int ok;
void input() {
  std::cin >> n >> m;
  if (n % 2 == 0)
    min = n / 2;
  else
    min = (n / 2) + 1;
  max = n;
  ok = 0;
  for (int i = min; i <= max; i++) {
    if (i % m == 0) {
      std::cout << i;
      ok = 1;
      break;
    }
  }
  if (ok == 0) std::cout << "-1";
}
int main() {
  input();
  return 0;
}
