#include <bits/stdc++.h>
using namespace std;
int calc(int x, int y) {
  x--;
  y--;
  int p = x / y;
  if (x % y) p++;
  return max(0, p) * 2 - 1;
}
int main() {
  int n, m, ans;
  scanf("%d%d", &m, &n);
  if (n == 1) return puts("-1"), 0;
  if (n >= m + m) return puts("1"), 0;
  if (n >= m) return puts(n == m ? "5" : "3"), 0;
  ans = 1 << 30;
  if (n >= 3 && n - 2 + n >= m) ans = min(ans, 6 + calc(m - n + 3, n));
  if (n >= 2 && n - 1 + n >= m) ans = min(ans, 8 + calc(m - n + 2, n));
  if (n >= 4)
    ans = min(ans,
              min(4 + calc(m - n + 2, n / 2), 8 + calc(m - n - n + 4, n / 2)));
  printf("%d\n", ans == 1 << 30 ? -1 : ans);
}
