#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int lowerbound = ceil(double(n) / 2);
  int result = ceil(double(lowerbound) / m);
  result *= m;
  if (result > n)
    cout << "-1";
  else
    cout << result;
  return 0;
}
