#include <stdio.h>

int main(void)
{
	long a, b, t;
	
	scanf("%ld %ld", &a, &b);
	
	if (a < b){
		t = a;
		a = b;
		b = t;
	}
	
	while (b != 0){
		t = a % b;
		a = b;
		b = t;
	}
	
	printf("%ld\n", a);
	
	return (0);
}