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