#include<bits/stdc++.h>
using namespace std;
int main()
{
    long M,N,t=1;
    cin>>M>>N;
	while(t){
	t=N%M;
	M=N;
    N=t;
	}
	cout<<N;		
	return 0;
}

/**************************************************************
	Problem: 1088
	User: ccf
	Language: C++
	Result: Wrong Answer
****************************************************************/