#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, steps = 0, sum = 0, twos = 0;
  cin >> n >> m;
  if (n < m)
    cout << -1;
  else {
    while (sum < n) {
      sum += 2;
      steps += 1;
      twos += 1;
    }
    if (sum > n) {
      sum -= 1;
      twos -= 1;
    }
    while (steps % m != 0) {
      twos -= 1;
      steps += 1;
      if (twos == -1) break;
    }
    if (twos == -1)
      cout << -1;
    else
      cout << steps;
  }
  return 0;
}
