#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int x = n / 2, y = n % 2, kq;
  kq = x + y;
  while ((kq % m) != 0) {
    if (x > 0) {
      --x;
      ++kq;
    } else {
      kq = -1;
      break;
    }
  }
  printf("%d", kq);
  fclose(stdin);
}
