#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  int half = m / 2;
  if (m < 2) {
    cout << -1;
    return 0;
  } else if (m == 3 && n == 5) {
    cout << 11;
    return 0;
  } else if (m == 2 && n >= 4) {
    cout << -1;
    return 0;
  } else if (m == 2 && n == 3) {
    cout << 11;
    return 0;
  } else if (m == 3 && n == 4) {
    cout << 9;
    return 0;
  } else if (m == 3 && n >= 5) {
    cout << -1;
    return 0;
  } else if (n * 2 <= m) {
    cout << 1;
    return 0;
  } else if (n <= m - 1) {
    cout << 3;
    return 0;
  } else if (2 * n + 4 <= 3 * m || n == m) {
    cout << 5;
    return 0;
  }
  int t = n, s = n, cnt = 0;
  t -= m - 2, s -= m - 2, cnt += 4;
  while (t > 0 && s > 0)
    if (t >= m && s >= m)
      t -= half - 1, s -= half - 1, cnt += 2;
    else
      t = 0, s = 0, cnt += 3;
  cout << cnt;
}
