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