#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
  scanf("%lld %lld", &n, &x);
  if (x == 0)
    printf("0\n");
  else if (x == n)
    printf("%lld\n", 3 * n);
  else
    printf("%lld\n", (n - 1) * 3);
  return 0;
}
