#include <bits/stdc++.h>
using namespace std;
bool visit[4000][4000];
int d[4000][4000];
int dx[] = {1, 0, -1}, dy[] = {-1, 1, 0};
int nd(int dir, int d) {
  if (dir == 0) {
    if (d == 1)
      return 2;
    else
      return 1;
  } else if (dir == 1) {
    if (d == 0)
      return 2;
    else
      return 0;
  } else {
    if (d == 0)
      return 1;
    else
      return 0;
  }
  return -1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, X;
  cin >> N >> X;
  memset(d, -1, sizeof d);
  for (int i = 0; i <= N; i++) {
    d[i][0] = 1;
    d[0][i] = 2;
    d[N - i][i] = 0;
  }
  long long ans = 0;
  int sy = X, sx = 0;
  int ny = X, nx = 0, dir = 0;
  do {
    nx += dx[dir];
    ny += dy[dir];
    if (d[ny][nx] != -1) {
      dir = nd(dir, d[ny][nx]);
    } else {
      d[ny][nx] = dir;
    }
    ans++;
  } while (!(nx == sx && ny == sy));
  cout << ans << endl;
}
