#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, k = -1;
  cin >> n >> m;
  for (int i = (n + 1) / 2; i <= n; ++i)
    if (i % m == 0) {
      k = i;
      break;
    }
  cout << k;
  return 0;
}
