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