#include <bits/stdc++.h>
using namespace std;
const int dx[6] = {-1, -1, 0, 1, 1, 0};
const int dy[6] = {0, 1, 1, 0, -1, -1};
int next_d(int d, int w) {
  if (w == 0) {
    return d % 3 == 1 ? (d + 4) % 6 : (d + 2) % 6;
  } else if (w == 1) {
    return d % 3 == 1 ? (d + 2) % 6 : (d + 4) % 6;
  } else if (w == 2) {
    return d % 3 == 0 ? (d + 2) % 6 : (d + 4) % 6;
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, X;
  cin >> N >> X;
  assert(N <= 1000);
  vector<vector<int>> tri(N + 1, vector<int>(N + 1, 0)),
      wall(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < (int)(N + 1); i++) tri[i][0] = 1, wall[i][0] = 0;
  for (int i = 0; i < (int)(N + 1); i++) tri[0][i] = 1, wall[0][i] = 1;
  for (int i = 0; i < (int)(N + 1); i++) tri[i][N - i] = 1, wall[i][N - i] = 2;
  int ans = 0, d = 1, x = X, y = 0;
  while (1) {
    ans++;
    x += dx[d], y += dy[d];
    assert(0 <= x and x <= N and 0 <= y and y <= N and x + y <= N);
    if (x == X and y == 0) break;
    if (tri[x][y] == 0) {
      tri[x][y] = 1;
      wall[x][y] = d % 3 == 0 ? 0 : d % 3 == 1 ? 2 : 1;
    } else {
      d = next_d(d, wall[x][y]);
    }
  }
  cout << ans << endl;
  return 0;
}
