#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  while (scanf("%d%d", &m, &n) != EOF) {
    if (n == 1) {
      printf("-1\n");
      continue;
    }
    if (n == 2) {
      if (m == 1)
        printf("1\n");
      else if (m == 2)
        printf("5\n");
      else if (m == 3)
        printf("11\n");
      else
        printf("-1\n");
      continue;
    }
    if (n == 3) {
      if (m == 1)
        printf("1\n");
      else if (m == 2)
        printf("3\n");
      else if (m == 3)
        printf("5\n");
      else if (m == 4)
        printf("9\n");
      else if (m == 5)
        printf("11\n");
      else
        printf("-1\n");
      continue;
    }
    int k = n / 2 - 1;
    if (n % 2 == 0) {
      printf("%d\n", (m - 2) / k * 2 + 1);
    } else {
      if (m + m <= n) {
        printf("1\n");
      } else if (m <= n - 1) {
        printf("3\n");
      } else if (m <= k * 3 + 2) {
        printf("5\n");
      } else if (m <= k * 4 + 3) {
        printf("7\n");
      } else {
        printf("%d\n", (m - 4) / k * 2 + 1);
      }
    }
  }
  return 0;
}
