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