#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXM = 1000000007;
const int MAX = 1e7;
const int des = 10000;
const int maxn = 5005;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = (n + 1) / 2; i <= n; i++) {
    if (i % m == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
