#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<(n);i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF 2000000000000
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define Int long long
#define hogea pair<pair<int,int>,int>

signed main(){
  int n;
  int x;
  cin>>n>>x;
  cout<<(n+x-__gcd(n,x))*2<<endl;
  return 0;
}
