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