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