#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, i, j, f;
  while (scanf("%d %d", &n, &m) != EOF) {
    s = 0;
    f = 0;
    if (n % 2 == 0)
      s = n / 2;
    else
      s = n / 2 + 1;
    while (1) {
      if (s % m == 0) {
        f = 1;
        break;
      } else {
        if (s == n) break;
        s += 1;
      }
    }
    if (f == 1)
      cout << s << endl;
    else
      cout << "-1" << endl;
  }
}
