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