#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
const bool TEST = false;
int main() {
  std::ifstream in("in.txt");
  if (TEST) {
    std::streambuf *cinbuf = std::cin.rdbuf();
    std::cin.rdbuf(in.rdbuf());
  }
  int n, m;
  int a, b;
  int res = -1;
  cin >> n >> m;
  int k = n / m;
  if (k == 0)
    res = -1;
  else {
    for (int i = 1; i <= k; i++) {
      b = n - i * m;
      if (i * m - b >= 0) {
        a = n - 2 * b;
        res = a + b;
        break;
      }
    }
  }
  cout << res;
  return 0;
}
