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