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