#include <bits/stdc++.h>
struct Node {
  int len_ab;
  int len_ac;
  int vec;
  struct Node *next;
};
struct Node *createNode(int ab, int ac, int vec) {
  struct Node *node = (struct Node *)malloc(sizeof(struct Node));
  node->len_ab = ab;
  node->len_ac = ac;
  node->vec = vec;
  node->next = NULL;
  return node;
}
void freeNode(struct Node *p) {
  if (p != NULL) freeNode(p->next);
  free(p);
}
void Add(struct Node *list, struct Node *node) {
  if (list == NULL)
    list = node;
  else {
    struct Node *p = list;
    while (p->next != NULL) {
      p = p->next;
    }
    p->next = node;
  }
}
int main(void) {
  int N, X;
  scanf("%d%d", &N, &X);
  int ans = 0;
  struct Node *list = createNode(X, 0, 0);
  int x = X;
  int y = 0;
  int vec = 0;
  for (int k = 1; k < N; k++) {
    Add(list, createNode(k, 0, 1));
    Add(list, createNode(0, k, 2));
    Add(list, createNode(k, N - k, 0));
  }
  while (1) {
    ans++;
    switch (vec) {
      case 0:
        x--;
        y++;
        break;
      case 1:
        x++;
        break;
      case 2:
        y--;
        break;
      default:
        break;
    }
    if (x == X && y == 0) break;
    int frag = 0;
    int vec2 = -1;
    struct Node *p = list;
    while (p != NULL) {
      if (x == p->len_ab && y == p->len_ac) {
        vec2 = p->vec;
        frag = 1;
        break;
      } else {
        p = p->next;
      }
    }
    if (frag == 1) {
      if (vec == 0) {
        if (vec2 == 1)
          vec = 2;
        else
          vec = 1;
      } else if (vec == 1) {
        if (vec2 == 0)
          vec = 2;
        else
          vec = 0;
      } else {
        if (vec2 == 0)
          vec = 1;
        else
          vec = 0;
      }
    }
    Add(list, createNode(x, y, vec));
  }
  printf("%d\n", ans);
  freeNode(list);
  return 0;
}
