#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%lld", &x)
#define sqr(x) (x) * (x)
#define f(i, a, b) for (int i = a; i <= b; i++)
#define pn(x) printf("%lld", x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))
int main()
{
LL n, x,min,max;
scan(n);
scan(x);
min = n < x ? n : x;
max = n > x ? n : x;
while(max%min){
int temp = max % min;
max = min;
min = temp;
}
pn(min);
return 0;
}