#include <bits/stdc++.h>
using namespace std;
long long int ret = 0;
long long int a, b;
void caseA();
void caseB();
void judge();
int main() {
  long long int n, x;
  cin >> n >> x;
  a = x;
  ret += a;
  b = n - x;
  ret += b;
  judge();
  cout << ret << endl;
  return 0;
}
void caseA() {
  ret += b * 2;
  a -= b;
  judge();
}
void caseB() {
  ret += a * 2;
  b -= a;
  judge();
}
void judge() {
  if (a > b)
    caseA();
  else if (a < b)
    caseB();
  else {
    ret += a;
  }
}
