#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 123;
const long long inf = 1e9 + 1;
const int mod = 1e9 + 7;
int n, m;
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n < m) {
    cout << -1;
    return 0;
  }
  long long k = n / 2;
  if (k * 2 != n) {
    k++;
  }
  while (k <= n) {
    if (k % m == 0) {
      break;
    }
    k++;
  }
  if (k > n) {
    cout << -1;
  } else {
    cout << k;
  }
  return 0;
}
