#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000000;
int n, m;
struct table {
  bool a[MAXN];
  bool &operator()(int i, int j) {
    if (i == 0) return a[j];
    if (j == m - 1) return a[m + i];
    if (i == n - 1) return a[n + m + j];
    return a[m * 2 + n + i];
  }
};
table a;
void next(int &i, int &j, int &ki, int &kj) {
  int step1;
  int step2;
  if (ki == 1)
    step1 = n - i - 1;
  else
    step1 = i;
  if (kj == 1)
    step2 = m - j - 1;
  else
    step2 = j;
  if (step1 == step2) {
    i += step1 * ki;
    j += step1 * kj;
    ki *= -1;
    kj *= -1;
  } else if (step1 < step2) {
    i += step1 * ki;
    j += step1 * kj;
    ki *= -1;
  } else {
    i += step2 * ki;
    j += step2 * kj;
    kj *= -1;
  }
  return;
}
int main() {
  int ans = 0;
  cin >> n >> m;
  for (int i_ = 0; i_ < n; i_ += n - 1)
    for (int j_ = 0; j_ < m; ++j_) {
      if (!a(i_, j_)) {
        int i = i_;
        int j = j_;
        ans++;
        int ki = (i == 0) ? 1 : -1;
        int kj = (j == 0) ? 1 : -1;
        a(i, j) = true;
        while (true) {
          next(i, j, ki, kj);
          if (a(i, j)) break;
          a(i, j) = true;
        }
        if (j_ != m - 1) {
          i = i_;
          j = j_;
          kj = 1;
          ki = (i == 0) ? 1 : -1;
          a(i, j) = true;
          while (true) {
            next(i, j, ki, kj);
            if (a(i, j)) break;
            a(i, j) = true;
          }
        }
      }
    }
  for (int j_ = 0; j_ < m; j_ += m - 1)
    for (int i_ = 0; i_ < n; ++i_) {
      if (!a(i_, j_)) {
        int i = i_;
        int j = j_;
        ans++;
        int ki = (i == 0) ? 1 : -1;
        int kj = (j == 0) ? 1 : -1;
        a(i, j) = true;
        while (true) {
          next(i, j, ki, kj);
          if (a(i, j)) break;
          a(i, j) = true;
        }
        if (i_ != n - 1) {
          i = i_;
          j = j_;
          ki = 1;
          kj = (j == 0) ? 1 : -1;
          a(i, j) = true;
          while (true) {
            next(i, j, ki, kj);
            if (a(i, j)) break;
            a(i, j) = true;
          }
        }
      }
    }
  cout << ans;
  return 0;
}
