#include <stdio.h>

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

  int n, m;
  scanf("%d%d", &n, &m);
  int r = 0;
  for (int z=0;z<n*m;z++)
    if (z / n == z % m && z / m == z % n)
      ++r;
  printf("%d\n", r);

  return 0;
}