#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, ans, x, y, first, last, sum, mx;
int a[101], b[101];
int main() {
  cin >> n >> m;
  x = (n + 1) / 2;
  for (i = x; i <= n; i++) {
    if (i % m == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
