int main(){
  long int a,b;
  scanf("%ld%ld",&a,&b);
  if(a>b){
    a%=b;
    b%=a;
    if(a<b) printf("%ld",a);
    else printf("%ld",b);
  }else{
    b%=a;
    a%=b;
    if(b<a) printf("%ld",b);
    else printf("%ld",a);
  }
  return 0;
}