#include <bits/stdc++.h>
using namespace std;
int n, m, pa[4000005];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int id(int x, int y) {
  if (x == 1)
    return y;
  else if (x == n)
    return 2 * m + n - 1 - y;
  else if (y == 1)
    return 2 * m + 2 * n - 2 - x;
  else if (y == m)
    return m + x - 1;
}
int Find(int x) { return (pa[x] == x) ? x : pa[x] = Find(pa[x]); }
void Merge(int x, int y) {
  if (Find(x) != Find(y)) pa[Find(x)] = Find(y);
}
int main() {
  int ans = 0;
  n = read(), m = read();
  for (register int i = 1; i <= 2 * (n + m) - 4; i++) pa[i] = i;
  if (n < m) do {
      n ^= m;
      m ^= n;
      n ^= m;
    } while (0);
  for (register int i = 1; i <= n; i++) {
    if (i <= m)
      Merge(id(i, 1), id(1, i)), Merge(id(i, m), id(1, m - i + 1));
    else
      Merge(id(i, 1), id(i - m + 1, m)), Merge(id(i, m), id(i - m + 1, 1));
    if (i + m - 1 < n)
      Merge(id(i, 1), id(m + i - 1, m)), Merge(id(i, m), id(m + i - 1, 1));
    else
      Merge(id(i, 1), id(n, n - i + 1)), Merge(id(i, m), id(n, m - n + i));
  }
  for (register int i = 1; i <= 2 * (m + n) - 4; i++) {
    if (pa[i] == i) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
