#include <bits/stdc++.h>
const int maxn = 1001000;
int n, m;
inline int get1(const int& x, const int& y) { return (x - y) + (n - 1); }
inline int get2(const int& x, const int& y) { return n + m - 1 + (x + y); }
int p[4 * maxn];
int getp(int u) {
  if (p[u] == u) {
    return u;
  } else {
    return p[u] = getp(p[u]);
  }
}
void unionp(int u, int v) {
  u = getp(u);
  v = getp(v);
  if (rand() % 2) {
    p[u] = v;
  } else {
    p[v] = u;
  }
}
bool a[4 * maxn];
int main() {
  std::cin >> n >> m;
  if (n > m) {
    std::swap(n, m);
  }
  int K = (n + m - 1) * 2;
  for (int i = 0; i < K; ++i) {
    p[i] = i;
  }
  int u, v;
  for (int y = 0; y < n; ++y) {
    u = get1(0, y), v = get2(0, y);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
    u = get1(n - 1 - y, n - 1), v = get2(n - 1 - y, n - 1);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
  }
  for (int x = 1; x <= m - n; ++x) {
    u = get1(x, 0), v = get2(x, 0);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
    u = get1(n - 1 + x, n - 1), v = get2(n - 1 + x, n - 1);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
  }
  for (int x = m - n + 1; x < m; ++x) {
    u = get1(x, 0), v = get2(x, 0);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
    u = get1(m - 1, m - 1 - x), v = get2(m - 1, m - 1 - x);
    if (getp(u) != getp(v)) {
      unionp(u, v);
    }
  }
  std::memset(a, false, sizeof(a));
  for (int i = 0; i < K; ++i) {
    a[getp(i)] = true;
  }
  int ans = 0;
  for (int i = 0; i < K; ++i) {
    if (a[i]) {
      ++ans;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
