#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = int(1e5) + 111;
const int INF = int(1e9) + 111;
const long long LINF = long long(1e18) + 111;
const long double EPS = 1e-7;
const long double PI = 3.141592653589793238462643;
const long long MOD = long long(1e9) + 9;
template <class T>
void writerLn(T x) {
  cout << x << "\n";
}
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
  for (auto &i : v) {
    in >> i;
  }
  return in;
}
template <typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
  for (auto &it : v) {
    out << it << " ";
  }
  return out;
}
template <typename T, typename F>
inline ostream &operator<<(ostream &out, const map<T, F> &v) {
  for (auto &it : v) {
    out << "(" << it.first << ":" << it.second << ") ";
  }
  return out;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T abs(T a) {
  return a >= 0 ? a : -a;
}
long long dp[10002][11];
map<int, vector<pair<int, int>>> mp;
int n, m;
vector<vector<int>> g;
int val;
int used[5020];
int p[5020];
set<pair<int, int>> G;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, x;
  cin >> n >> x;
  if (2 * x == n)
    cout << x * 3;
  else if (2 * x > n) {
    cout << x + (n - x) * 6;
  } else if (2 * x < n) {
    cout << 3 * x + (n - x) + 3 * (n - 2 * x);
  }
  return 0;
}
