#include<iostream>
using namespace std;
int Farm(int a, int b)
{
if (a % b == 0 && a / b > 0) //基线条件
{
return b;
}
else if (b % a == 0 && b / a > 0) //基线条件
{
return a;
}
else //递归条件
{
if (a > b)
{
int x = a;
for (; x > b;)
{
x -= b;
}
return Farm(x, b);
}
if (b > a)
{
int y = b;
for (; y > a;)
{
y -= a;
}
return Farm(a, y);
}
}
}
int main()
{
int a, b;
cin >> a >> b;
cout << Farm(a, b);
return 0;
}