#include <bits/stdc++.h>
using namespace std;

int sum(a,b){
  if(a==b){
    return sum(a,b) + a;
  }
  if(a>b){
    return sum(a-b,b) + 2*b;
  }
  if(a<b){
    return sum(a,b-a) + 2*a;
  }
}

int main(){
  int n,x;
  cin >> n >> x;
  cout << sum(x,n-x)+n << endl;
}
