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