#include <stdio.h>

int gcd(int a, int b)
{
  while (b)
  {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main()
{
  freopen("cinema.in", "rt", stdin);
  freopen("cinema.out", "wt", stdout);

  int n, m;
  scanf("%d%d", &n, &m);
  printf("%d\n", 1 + gcd(n - 1, m - 1));

  return 0;
}
