#include <bits/stdc++.h>
using namespace std;
const int big = INT_MAX;
const int small = INT_MIN;
const long long Big = LONG_MAX;
const long long Small = LONG_MIN;
const int FindMax = 4294967295;
const double e = 2.7182818284590452353602874713526624977572;
const double pi = 3.1415926535897932384626433832795028841971;
const double fi = 1.6180339887498948482045868343656381177203;
long long input() {
  long long n;
  scanf("%I64d", &n);
  return n;
}
string _input() {
  string s;
  cin >> s;
  return s;
}
int main() {
  int n = int(input());
  int m = int(input());
  int lower_bound = (n + 1) / 2;
  int ans = (lower_bound + m - 1) / m * m;
  if (ans > n) ans = -1;
  printf("%i\n", ans);
}
