#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m > n)
    cout << -1;
  else if (n == m)
    cout << n;
  else {
    int x = n;
    while (x) {
      int div = x / 2;
      int y = div + (n - (div * 2));
      if (y % m == 0) {
        cout << y;
        break;
      } else
        x -= 2;
    }
  }
}
