#include <bits/stdc++.h>
using namespace std;
const int Inf = 1 << 30;
inline void out(int answer) {
  cout << answer << endl;
  exit(0);
}
inline int lastTof(int m, int n) {
  if (m <= n) {
    if (2 * m <= n) return 1;
    if (m == n) return 5;
    return 3;
  }
  return Inf;
}
inline int solve(int m, int n) {
  int ans = 0;
  int ret = Inf;
  while (1) {
    ret = min(ret, ans + lastTof(m, n));
    m -= n / 2;
    ans++;
    if (m <= 0) break;
    m++;
    ans++;
  }
  return min(ret, ans);
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> m >> n;
  if (n == 1) out(-1);
  if (m * 2 <= n) out(1);
  if (m + 1 <= n) out(3);
  if (n == 2) {
    if (m > 3) out(-1);
    if (m == 3) out(11);
  }
  if (n == 3) {
    if (m > 5) out(-1);
    if (m == 5) out(11);
    if (m == 4) out(9);
  }
  if (m == n) out(5);
  cout << min(solve(m - n + 2, n) + 4, solve(m, n)) << endl;
  return 0;
}
