#include <iostream>
using namespace std;
#define min(a,b) (a < b ? a : b)
int minop(int x, int y){
if(x == 1)
return y;
if(y == 1)
return x;
int m = min(x,y);
if(m == x)
y = y - m;
else
x = x - m;
return m + minop(x,y);
}
int main(){
int x,y;
cin >> x >> y;
cout << minop(x,y);
}