#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int maxm = 1e6 + 10;
const int MOD = 1e9 + 7;
bool vis[maxm];
int n, m, y;
void go(int _x, int _d) {
  int x = _x;
  int mx = _d, my = 1;
  do {
    vis[x] = true;
    do {
      int dx, dy;
      if (mx == -1)
        dx = x;
      else
        dx = m - x - 1;
      if (my == -1)
        dy = y;
      else
        dy = n - y - 1;
      dx = min(dx, dy);
      dy = min(dy, dx);
      y += my * dy;
      x += mx * dx;
      if (y == 0 || y == n - 1) my = -my;
      if (x == 0 || x == m - 1) mx = -mx;
    } while (y != 0);
  } while (vis[x] == false);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (vis[i]) continue;
    cnt++;
    if (i == 0)
      go(i, 1);
    else if (i == n)
      go(i, -1);
    else
      go(i, 1), go(i, -1);
  }
  cout << cnt << endl;
  return 0;
}
