#include <bits/stdc++.h>
using namespace std;
long long n, m;
stack<int> s;
void trysolve(int r, int c, int init, int left, int down) {
  if (!init && r == 0) {
    s.push(c);
    return;
  }
  if (c == 0 && left) {
    trysolve(r, c, init, 0, down);
    return;
  }
  if (c == n - 1 && !left) {
    trysolve(r, c, init, 1, down);
    return;
  }
  if (r == m - 1 && down) {
    trysolve(r, c, init, left, 0);
    return;
  }
  if (left) {
    if (down) {
      int rlimit = m - r - 1;
      int climit = c;
      int x = min(rlimit, climit);
      trysolve(r + x, c - x, 0, left, down);
    } else {
      int climit = c;
      int rlimit = r;
      int x = min(rlimit, climit);
      trysolve(r - x, c - x, 0, left, down);
    }
  } else {
    if (down) {
      int rlimit = m - r - 1;
      int climit = n - c - 1;
      int x = min(rlimit, climit);
      trysolve(r + x, c + x, 0, left, down);
    } else {
      int rlimit = r;
      int climit = n - c - 1;
      int x = min(rlimit, climit);
      trysolve(r - x, c + x, 0, left, down);
    }
  }
}
int main() {
  cin >> n >> m;
  if (m > n) swap(n, m);
  int beaten[1000050];
  for (int(i) = 0; (i) < (1000050); ++(i)) beaten[i] = 0;
  long long ret = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    if (beaten[i]) continue;
    ++ret;
    s.push(i);
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      if (beaten[t]) continue;
      beaten[t] = 1;
      trysolve(0, t, 1, 1, 1);
      trysolve(0, t, 1, 0, 1);
    }
  }
  cout << ret << endl;
  return 0;
}
