#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  if (m > n) {
    cout << -1;
    return 0;
  }
  int cnt = 0;
  ans = n / 2;
  if (((n % 2) == 0) && ((ans % m) == 0))
    cout << ans;
  else {
    for (;;) {
      ans++;
      if (ans % m == 0) break;
    }
    cout << ans;
  }
  return 0;
}
