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