#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[100],b=0;
    cin>>a[0]>>a[1];
    int i=1
    for(;;i++){
        a[i+1]=a[i-1]%a[i];
        if(a[i]<a[i+1])swap(a[i],a[i+1]);
        if(a[i+1]==0) break;
    }
    for(int j=1;j<i;j+=2) b+=a[j];
    cout<<b<<endl;
    return 0;
}
        