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