#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, x, y, z, i;
  cin >> n >> m;
  if (n % 2 == 0)
    x = n / 2;
  else
    x = (n / 2) + 1;
  for (i = x; i <= n; i++) {
    if (i % m == 0) {
      cout << i << endl;
      break;
    } else if (m > n) {
      cout << "-1" << endl;
      break;
    }
  }
}
