#include <bits/stdc++.h>
using namespace std;
long long int mn = 1e18, mx = -1e18;
const long long int mv = 1000005;
long long int n, x, k;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cin >> n >> x;
  k = n - x;
  if (k > x) {
    cout << x * 3 + (k) + (k - x) * 3;
    return 0;
  }
  if (k == x) {
    cout << x * 3;
    return 0;
  }
}
