#include <bits/stdc++.h>
using namespace std;
void sor(vector<long long> &x) { sort(x.begin(), x.end()); }
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
list<long long> a[5];
void bfs(int src) {
  queue<int> q;
  bool *vis = new bool[5 + 1]{0};
  q.push(src);
  vis[src] = true;
  while (!q.empty()) {
    int node = q.front();
    cout << node << " ";
    q.pop();
    for (int n : a[node]) {
      if (!vis[n]) {
        q.push(n);
        vis[n] = true;
      }
    }
  }
}
long long min(long long x, long long y) {
  if (x > y) {
    return y;
  } else {
    return x;
  }
}
int main() {
  double n, x;
  cin >> n >> x;
  double ans = 2 * x + n + 3 * (gcd(n, x));
  cout << ans;
  return 0;
}
