#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = (n / 2) + (n & 1);
  for (int i = ans; i <= n; ++i) {
    if (i % m == 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1;
  return 0;
}
