#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (m > n) {
      cout << "-1\n";
      continue;
    } else {
      int x = n / 2;
      if ((n % 2)) x++;
      for (int i = 0; i <= 10; i++) {
        if (!(x % m)) {
          cout << x << "\n";
          break;
        }
        x++;
      }
    }
  }
  return 0;
}
