#include <bits/stdc++.h>
int main() {
  int x, y, x1 = 0, y1 = 0, n, k = 0;
  do {
    scanf("%d%d", &x, &n);
  } while (x < 1 || n < 1 || n > 100000 || x > 100000);
  y = x;
  if ((x == 4 && n == 2) || (x > 5 && n < 4) || x <= n || n < 4) {
    printf("%d\n", (x == n && x != 1)                           ? k = 5
                   : n / x >= 2                                 ? k = 1
                   : x < n                                      ? k = 3
                   : (x == 4 && n == 3)                         ? k = 9
                   : ((x == 5 && n == 3) || (x == 3 && n == 2)) ? k = 11
                                                                : k = -1);
    exit(0);
  }
  y = x -= n - 2;
  y1 = x1 += n - 2;
  k = 4;
  if (x <= n / 2) {
    y1 = x1 += x;
    y = x -= x;
    printf("%d", k + 1);
    exit(0);
  }
  while (y > n) {
    y = x -= n / 2 - 1;
    y1 = x1 += n / 2 - 1;
    k += 2;
  }
  y == n ? k += 5 : k += 3;
  y1 = x1 += x;
  y = x -= x;
  printf("%d", k);
  return 0;
}
