#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  int two = n / 2, one = n % 2;
  int mod = m - ((two + one) % m);
  mod %= m;
  if (two < mod) {
    cout << -1 << endl;
  } else {
    cout << two + one + mod << endl;
  }
}
