#include <bits/stdc++.h>
using namespace std;
int main(void) {
  const int INF = 123456789;
  int m, n, res = INF, base = 0;
  scanf("%d%d", &m, &n);
  do {
    if (n == 1) {
      res = min(res, INF);
    } else if (n >= m * 2) {
      res = min(res, base + 1);
    } else if (n - 1 >= m) {
      res = min(res, base + 3);
    } else if (n >= m || n * 3 >= 2 * m + 4) {
      res = min(res, base + 5);
    } else if (2 * n - 3 >= m) {
      res = min(res, base + 7);
    } else if (2 * n - 2 >= m) {
      res = min(res, base + 9);
    } else if (2 * n - 1 >= m) {
      res = min(res, base + 11);
    } else
      res = min(res, INF);
    if (n >= 4 && m >= n / 2 - 1) {
      base += 2;
      m -= (n / 2 - 1);
    } else
      break;
  } while (1);
  if (res == INF)
    puts("-1");
  else
    printf("%d\n", res);
  return 0;
}
