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