#include <bits/stdc++.h>
int main() {
  int n, m, temp;
  scanf("%d %d", &n, &m);
  temp = n / 2;
  if (temp * 2 != n) {
    temp++;
  }
  int a = temp / m;
  if (a * m != temp) {
    a++;
  }
  int res = (a)*m;
  if (res <= n)
    printf("%d", res);
  else
    printf("-1");
}
