#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> m >> n;
  if (n == 1) {
    cout << -1;
    return 0;
  }
  if (n == 2 && m == 3) {
    cout << 11;
    return 0;
  }
  if (n == 3 && m == 5) {
    cout << 11;
    return 0;
  }
  int sol = 0, ok = 1;
  while (1) {
    if (n >= m + m) {
      cout << sol + 1;
      break;
    }
    if (n == m) {
      cout << sol + 5;
      break;
    }
    if (n > m) {
      cout << sol + 3;
      break;
    }
    if (ok == 1) {
      m -= n - 2;
      sol += 4;
      ok = 0;
    } else {
      if (n / 2 == 1) {
        cout << -1;
        break;
      }
      m -= (n / 2 - 1);
      sol += 2;
    }
  }
  return 0;
}
