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