#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, X, cnt = 0;
  bool finish = false;
  cin >> N >> X;
  long long a1 = X, a2 = N, b1 = 0, b2 = N, c1 = 0, c2 = N;
  long long a = X, b = N - X, c = N, dir = 1;
  while (!finish) {
    if (dir == 1) {
      while (b++, c--, cnt++, b < b2 && c > c1)
        ;
      if (b == b2) {
        c1 = c;
        dir = 3;
      } else {
        b1 = b;
        dir = 2;
      }
    }
    if (dir == 2) {
      while (c++, a--, cnt++, c < c2 && a > a1)
        ;
      if (c == N && a == X) {
        finish = true;
      } else if (c == c2) {
        a2 = a;
        dir = 1;
      } else {
        c1 = c;
        dir = 3;
      }
    }
    if (dir == 3) {
      while (a++, b--, cnt++, a < a2 && b > b1)
        ;
      b1 = b;
      dir = 2;
    }
  }
  cout << cnt << endl;
  return 0;
}
