#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, m, i, j, k = 0, a, b;
  cin >> t >> m;
  if (t % 2 == 0) {
    a = t / 2;
    b = a + 1;
  } else {
    a = (t / 2) + 1;
    b = a;
  }
  while (b--) {
    if (a % m == 0) {
      cout << a << endl;
      k = 1;
      break;
    } else
      a++;
  }
  if (k == 0) cout << "-1" << endl;
  return 0;
}
