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