#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, X;
  cin >> N >> X;
  long long a, b, c, d, e, f, ans = 0;
  a = d = N - X;
  b = e = 0;
  c = f = X;
  ans += N;
  int type = 0;
  while (type < 3) {
    if (type == 0) {
      if (a < c) {
        type = 2;
        ans += a;
        d = 0;
        e = a;
        f -= a;
      } else if (a > c) {
        type = 1;
        ans += c;
        a -= c;
        b = c;
        c = 0;
      } else {
        type = 3;
        ans += a;
      }
    } else if (type == 1) {
      type = 0;
      ans += b;
      b = 0;
      c = f;
      d -= f;
    } else if (type == 2) {
      type = 0;
      ans += a;
      c -= a;
      d = a;
      e = 0;
    }
  }
  cout << ans;
}
