#include <bits/stdc++.h>
using namespace std;
unsigned long long n, p = 0, i, j, l, m = 0, c = 0, d, y = 0, to = 0,
                      ma = INT_MAX;
int main() {
  cin >> n >> m;
  if (n < m)
    cout << -1 << endl;
  else {
    y = ceil(n / 2);
    for (i = y; i >= 0; i--) {
      to = i + (n - (i * 2));
      if (to % m == 0) {
        cout << to << endl;
        break;
      }
    }
  }
  return 0;
}
