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