#include <stdio.h>
#include <stdlib.h>

int main(){
        int x,y,z;

        scanf("%d %d", &y, &x);
        while(x % y != 0){
                z = x % y;
                x = y;
                y = z;
        }
        printf("%d\n", y);
return 0;
}