#include <bits/stdc++.h>
using namespace std;
const int SZ = 120;
struct st {
  int x, y, s;
  st(int x_ = 0, int y_ = 0, int s_ = 0) : x(x_), y(y_), s(s_) {}
};
int res[SZ][SZ][2];
int n, m;
queue<st> Q;
bool f(int a, int b) { return b == 0 || a <= b; }
void go() {
  Q.push(st(m, m, 0));
  memset(res, -1, sizeof(res));
  res[m][m][0] = 0;
  while (!Q.empty()) {
    st a = Q.front();
    Q.pop();
    for (int i = 0; i < a.x + 1; ++i)
      for (int j = 0; j < a.y + 1; ++j) {
        if (!i && !j) continue;
        if (!f(a.x - i, a.y - j) || !f(i, j) || !f(m - a.x + i, m - a.y + j) ||
            i + j > n)
          continue;
        if (res[m - a.x + i][m - a.y + j][a.s ^ 1] == -1) {
          res[m - a.x + i][m - a.y + j][a.s ^ 1] = res[a.x][a.y][a.s] + 1;
          Q.push(st(m - a.x + i, m - a.y + j, a.s ^ 1));
        }
      }
  }
  printf("%d\n", res[m][m][1]);
}
int N = 20;
int ans[1 << 10][1 << 10];
int dx[] = {2, 1, 0, 1};
int main() {
  scanf("%d%d", &m, &n);
  if (n <= 3) {
    if (m > 10)
      puts("-1");
    else
      go();
    return 0;
  }
  vector<int> v(3, 0);
  int x = 1;
  while ((int)v.size() < n + 10) {
    v.push_back(x);
    v.push_back(x);
    ++x;
  }
  int was = 0;
  int cur = 0;
  while (true) {
    int add = cur < 4 ? v[n - 1 + dx[cur]] : v[n - 1];
    if (was + add >= m) {
      printf("%d\n", cur * 2 + 1);
      return 0;
    }
    was += add;
    ++cur;
  }
  freopen("output.txt", "w", stdout);
  for (int m = 1; m < 100 + 1; ++m)
    for (int n = 1; n < N + 1; ++n) {
      Q.push(st(m, m, 0));
      memset(res, -1, sizeof(res));
      res[m][m][0] = 0;
      while (!Q.empty()) {
        st a = Q.front();
        Q.pop();
        for (int i = 0; i < a.x + 1; ++i)
          for (int j = 0; j < a.y + 1; ++j) {
            if (!i && !j) continue;
            if (!f(a.x - i, a.y - j) || !f(i, j) ||
                !f(m - a.x + i, m - a.y + j) || i + j > n)
              continue;
            if (res[m - a.x + i][m - a.y + j][a.s ^ 1] == -1) {
              res[m - a.x + i][m - a.y + j][a.s ^ 1] = res[a.x][a.y][a.s] + 1;
              Q.push(st(m - a.x + i, m - a.y + j, a.s ^ 1));
            }
          }
      }
      printf("%3d ", res[m][m][1]);
      if (res[m][m][1] != -1) ++ans[n][res[m][m][1]];
      if (n == N) puts("");
    }
  return 0;
}
