#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int di[] = {1, 1, -1, -1};
const int dj[] = {1, -1, -1, 1};
int a, b, c, d, i, j, n, m, k;
bool used_top[1000001][4], used_bottom[1000001][4], used_left[1000001][4],
    used_right[1000001][4];
queue<pair<pair<int, int>, int> > q;
inline int bad(int ci, int cj) {
  int ans = 0;
  if (ci < 0 || ci >= n) ++ans;
  if (cj < 0 || cj >= m) ++ans;
  return ans;
}
void bfs(int s, int bd) {
  int bi = 0, bj = s;
  int d = bd;
  while (!q.empty()) q.pop();
  q.push(make_pair(make_pair(bi, bj), d));
  while (!q.empty()) {
    int ci = q.front().first.first, cj = q.front().first.second,
        cd = q.front().second;
    q.pop();
    if (!ci && used_top[cj][cd]) continue;
    if (ci == n - 1 && used_bottom[cj][cd]) continue;
    if (!cj && used_left[ci][cd]) continue;
    if (cj == m - 1 && used_right[ci][cd]) continue;
    if (!ci) used_top[cj][cd] = 1;
    if (ci == n - 1) used_bottom[cj][cd] = 1;
    if (!cj) used_left[ci][cd] = 1;
    if (cj == m - 1) used_right[ci][cd] = 1;
    int ni = ci + di[cd], nj = cj + dj[cd];
    int b = bad(ni, nj);
    if (b == 2) {
      q.push(make_pair(make_pair(ci, cj), (cd + 2) % 4));
      continue;
    } else if (b == 1) {
      if (!ci || ci == n - 1) {
        if (cd == 0)
          cd = 3;
        else if (cd == 1)
          cd = 2;
        else if (cd == 2)
          cd = 1;
        else if (cd == 3)
          cd = 0;
      } else {
        if (cd == 0)
          cd = 1;
        else if (cd == 1)
          cd = 0;
        else if (cd == 2)
          cd = 3;
        else if (cd == 3)
          cd = 2;
      }
      q.push(make_pair(make_pair(ci, cj), cd));
    } else {
      int bl = 1000000000, gi = -1, gj = -1;
      if (di[cd] < 0 && ci < bl) {
        bl = ci;
        gi = 0;
        gj = cj + bl * dj[cd];
      }
      if (di[cd] > 0 && n - ci - 1 < bl) {
        bl = n - ci - 1;
        gi = n - 1;
        gj = cj + bl * dj[cd];
      }
      if (dj[cd] < 0 && cj < bl) {
        bl = cj;
        gj = 0;
        gi = ci + bl * di[cd];
      }
      if (dj[cd] > 0 && m - cj - 1 < bl) {
        bl = m - cj - 1;
        gj = m - 1;
        gi = ci + bl * di[cd];
      }
      q.push(make_pair(make_pair(gi, gj), cd));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int _n((m)-1), i(0); i <= _n; i++) {
    if (used_top[i][0] || used_top[i][1] || used_top[i][2] || used_top[i][3])
      continue;
    ++c;
    bfs(i, 0);
    bfs(i, 1);
  }
  printf("%d\n", c);
}
