#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long minv = n / 2 + (n % 2 == 1);
  long long maxv = n;
  long long ms = minv / m;
  if (ms * m < minv) ms++;
  if (ms * m >= minv && ms * m <= maxv)
    cout << ms * m << endl;
  else
    cout << -1 << endl;
  return 0;
}
