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

/**************************************************************
	Problem: 1088
	User: ccf
	Language: C++
	Result: Accepted
	Time:8 ms
	Memory:2072 kb
****************************************************************/