#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll N, K;
  cin >> N >> K;
  if (N % 2 == 1) {
    cout << (N - 1) * 3 << endl;
    return 0;
  }
  ll D = min(N - K, K);
  ll ans = (N - D) * 3;
  cout << -1 << endl;
  return 0;
}
