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