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