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