#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << -1 << endl;
  } else if (m == 2) {
    if (n == 1)
      cout << 1 << endl;
    else if (n == 2)
      cout << 5 << endl;
    else if (n == 3)
      cout << 11 << endl;
    else
      cout << -1 << endl;
  } else if (m == 3) {
    if (n == 1)
      cout << 1 << endl;
    else if (n == 2)
      cout << 3 << endl;
    else if (n == 3)
      cout << 5 << endl;
    else if (n == 4)
      cout << 9 << endl;
    else if (n == 5)
      cout << 11 << endl;
    else
      cout << -1 << endl;
  } else {
    if (m & 1) {
      int delta = m / 2;
      if (n <= delta)
        cout << 1 << endl;
      else if (n <= 2 * delta)
        cout << 3 << endl;
      else if (n <= 3 * delta - 1)
        cout << 5 << endl;
      else if (n <= 4 * delta - 1)
        cout << 7 << endl;
      else {
        int k = 4 * delta - 1;
        delta--;
        int ans = 7;
        while (k < n) {
          k += delta;
          ans += 2;
        }
        cout << ans << endl;
      }
    } else {
      int ans = 1;
      int delta = m / 2 - 1;
      int k = delta + 1;
      while (k < n) {
        k += delta;
        ans += 2;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
