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