#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  int kol = 0;
  if (n % 2 == 1) {
    n = n - 1;
    kol++;
  }
  while (true) {
    if (((n / 2) + kol) % a == 0) {
      cout << (n / 2) + kol;
      break;
    }
    if (n == 0) {
      cout << "-1";
      break;
    }
    n = n - 2;
    kol = kol + 2;
  }
}
