#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
int c[2000004];
int d[2000003];
int n, m;
inline int szuk(int x) {
  if (c[x] == x) return x;
  int a = szuk(c[x]);
  c[x] = a;
  return a;
}
inline void unia(int x, int y) {
  ;
  int a = szuk(x), b = szuk(y);
  c[a] = b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  if (m < n) swap(m, n);
  for (int i = 0; i < 2 * m + 3; i++) c[i] = i;
  d[1] = n;
  int ro = 1;
  for (int i = 2; i <= m; i++) {
    if (d[i - 1] == m) {
      ro = -1;
    } else if (d[i - 1] == 1)
      ro = 1;
    d[i] = d[i - 1] + ro;
    ;
  }
  for (int i = 1; i <= m; i++) unia(i, m + d[i]);
  for (int i = 1; i <= m; i++) unia(m - i + 1, m + m - d[i] + 1);
  d[m] = m - n + 1;
  for (int i = m - 1; i >= 1; i--) {
    if (d[i + 1] == m) {
      ro = -1;
    } else if (d[i + 1] == 1)
      ro = 1;
    d[i] = d[i + 1] + ro;
    ;
  }
  for (int i = 1; i <= m; i++) unia(i, m + d[i]);
  for (int i = 1; i <= m; i++) unia(m - i + 1, m + m - d[i] + 1);
  int ile = 0;
  for (int i = 1; i <= 2 * m; i++)
    ;
  for (int i = 1; i <= 2 * m; i++)
    if (szuk(i) == i) ile++;
  cout << ile;
  return 0;
}
