#include <bits/stdc++.h>
using namespace std;
int main() {
  int optimize;
  int n, m;
  cin >> n >> m;
  if (n < m) {
    cout << "-1" << endl;
    return 0;
  }
  optimize = (n % 2) + (n / 2);
  while (optimize % m != 0) {
    optimize++;
    n = n - 2;
    {
      if (n <= 1 && optimize % m != 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  cout << optimize << endl;
  return 0;
}
