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