#include <stdio.h>
int main(){
        int m,n,o;
        scanf("%d %d",&m,&n);
        if( m < n){
                o = m;
                m = n;
                n = o;
        }
        o = m % n;
        m = n;
        n = o;
        o = m % n;
        m = n;
        n = o;
        if(n == 0) printf("%d\n",m);
return 0;
}