#include <bits/stdc++.h>
int n, m;
int main() {
  int t;
  scanf("%d%d", &n, &m);
  while (true) {
    if (n > m) {
      t = n;
      n = m;
      m = t;
    }
    if (n == m || n == 2) {
      printf("%d\n", n);
      break;
    }
    m = m % (n - 1);
    if (m == 0)
      m = n - 1;
    else if (m == 1)
      m = n;
  }
  return 0;
}
