#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  if (m > n)
    cout << -1;
  else if (m == n)
    cout << n;
  else {
    long long int x, y;
    for (y = (n / 2); y >= 0; y--) {
      if (n - y >= 0) {
        x = n - 2 * y;
        if ((x + y) % m == 0) {
          cout << x + y;
          break;
        }
      }
    }
  }
}
