#include <bits/stdc++.h>
using namespace std;
void P(int x) {
  cout << x;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int ans = 0, m, n, f = 0;
  cin >> m >> n;
  if (n == 1) P(-1);
  if (n == 2 && m == 3) P(11);
  if (n == 3 && m == 5) P(11);
  for (;;) {
    if (n >= m + m) P(ans + 1);
    if (n >= m) P(ans + (n == m ? 5 : 3));
    if (!f)
      m -= n - 2, ans = 4, f = 1;
    else {
      if (n / 2 == 1) P(-1);
      m -= n / 2 - 1, ans += 2;
    }
  }
}
