#include <bits/stdc++.h>
int main() {
  int x;
  int y;
  scanf("%d %d", &x, &y);
  if (x < y) {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
  }
  int r;
  r = x % y;
  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  printf("%d\n", y);
  return 0;
}
