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