#include <bits/stdc++.h>
bool isprime(long long int n) {
  if (n < 2) return 0;
  long long int i = 2;
  while (i * i <= n) {
    if (n % i == 0) return 0;
    i++;
  }
  return 1;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long int n, t, count = 0, sum = 0, result, i, j, k;
  bool is;
  string s;
  cin >> n >> t;
  if (t > n) {
    cout << -1 << endl;
    return 0;
  }
  n = n / 2 + (n % 2);
  if (n % t != 0) {
    n = (n / t) + 1;
    n = n * t;
  }
  cout << n << endl;
  return 0;
}
