#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int min_steps = (n + 1) / 2;
  int q = (min_steps + m - 1) / m;
  int k = q * m;
  printf("%d\n", (k > n ? -1 : k));
  return 0;
}
