int main() { int m,n; scanf("%d %d",&m,&n); while(1) { if(n>m) n-=m; else if(m>n) m-=n; else { printf("%d",m); break; } } return 0; }