#include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 60;
const long long dx[] = {1, 0, -1}, dy[] = {0, 1, -1}, dv[3] = {2, 2, 1};
bool field[1005][1005];
long long n, x, ans;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x;
  long long tx = 0, ty = x, v = 0;
  do {
    field[tx][ty] = true;
    tx += dx[v];
    ty += dy[v];
    ans++;
    if (tx == ty || ty == n || tx == 0) {
      v++;
      v %= 3;
    } else if (field[tx][ty]) {
      v = dv[v];
    }
  } while (tx != 0 || ty != x);
  cout << ans << endl;
}
