#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  long long a = x;
  long long b = n - x;
  long long c = x;
  long long d = x;
  long long e = n - 2 * x;
  e = 2 * (e * (a / e)) - e;
  cout << a + b + c + d + e << endl;
  return 0;
}
