#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 4000005;
int n, m, fa[maxn];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  fa[x] = y;
}
int ID(int x, int y) {
  if (x == 1) return y;
  if (y == m) return m + x - 1;
  if (x == n) return 2 * m + n - 1 - y;
  return 2 * m + 2 * n - 2 - x;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= 2 * m + 2 * n - 4; i++) fa[i] = i;
    if (n < m) swap(n, m);
    for (int i = 1; i <= n; i++) {
      if (i <= m)
        unite(ID(i, 1), ID(1, i)), unite(ID(i, m), ID(1, m - i + 1));
      else
        unite(ID(i, 1), ID(i - m + 1, m)), unite(ID(i, m), ID(i - m + 1, 1));
      if (i >= n - m + 1)
        unite(ID(i, 1), ID(n, n - i + 1)), unite(ID(i, m), ID(n, m - n + i));
      else
        unite(ID(i, 1), ID(m + i - 1, m)), unite(ID(i, m), ID(m + i - 1, 1));
    }
    int ans = 0;
    for (int i = 1; i <= 2 * m + 2 * n - 4; i++)
      if (fa[i] == i) ans++;
    printf("%d\n", ans);
  }
  return 0;
}
