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