#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;
int n, m;
vector<int> v[nax];
bool bylo[nax];
int ogarnij(int i) {
  if (n >= i) {
    int poz = n - i + 1;
    if (m + 1 - poz >= n)
      return poz + n - 1;
    else
      return m - (n - (m + 1 - poz));
  } else {
    int poz = i - n + 1;
    if (poz >= n) return poz - n + 1;
    return n - poz + 1;
  }
  return -1;
}
int ogarnij2(int i) {
  if (m + 1 - i >= n) {
    int poz = i + n - 1;
    if (m + 1 - poz >= n)
      return poz + n - 1;
    else
      return m - (n - (m + 1 - poz));
  } else {
    int poz = m - (n - (m + 1 - i));
    if (poz >= n) return poz - n + 1;
    return n - poz + 1;
  }
  return -1;
}
void dfs(int x) {
  bylo[x] = true;
  for (auto i : v[x])
    if (!bylo[i]) dfs(i);
}
int main(int argc, char* argv[]) {
  debug = argc > 1;
  scanf("%d%d", &n, &m);
  if (m < n) swap(n, m);
  for (int i = 1; i <= m; ++i) {
    v[i].push_back(ogarnij(i));
    v[i].push_back(ogarnij2(i));
  }
  int res = 0;
  for (int i = 1; i <= m; ++i)
    if (!bylo[i]) {
      res++;
      dfs(i);
    }
  printf("%d\n", res);
  return 0;
}
