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