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