#include <bits/stdc++.h>
using namespace std;
int N, K, M;
int main() {
  scanf("%d%d", &N, &K);
  if (K <= 1)
    printf("-1\n");
  else if (K >= 2 * N)
    printf("1\n");
  else if (K > N)
    printf("3\n");
  else if (N == K)
    printf("5\n");
  else if (K == 2) {
    if (N == 3)
      printf("11\n");
    else
      printf("-1\n");
  } else if (K == 3) {
    if (N == 4)
      printf("9\n");
    else if (N == 5)
      printf("11\n");
    else
      printf("-1\n");
  } else {
    N -= (K - 2);
    M = 4;
    if (K >= 2 * N)
      ++M;
    else if (K > N)
      M += 3;
    else if (K == N)
      M += 5;
    else {
      N -= K;
      M += 2 * (N / (K / 2 - 1));
      N %= (K / 2 - 1);
      N += K;
      if (N > K) {
        N -= (K / 2 - 1);
        M += 2;
      }
      if (K >= 2 * N)
        ++M;
      else if (K > N)
        M += 3;
      else
        M += 5;
    }
    printf("%d\n", M);
  }
}
