#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = (n + 1) / 2; i <= n; i++)
    if (i % m == 0) return cout << i << '\n', 0;
  cout << "-1\n";
  return 0;
}
