#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10;
int s[N], h[N], n, m, ans, st;
bool vis[N];
int id(int x, int y) {
  if (x == 1 && y < m) return y;
  if (y == m && x < n) return m + x - 1;
  if (x == n && y > 1) return n + m - 2 + m - y + 1;
  return 2 * m + n - 3 + n - x + 1;
}
void dfs(int x, int y, int d) {
  int tmp = id(x, y);
  if (vis[tmp] && st != 2) {
    return;
  }
  vis[tmp] = 1;
  if ((x == 1 || x == n) && (y == 1 || y == m) && !st) return;
  st = 0;
  int tx, ty;
  if (d == 1) {
    if (x == 1)
      tx = min(n, m - y + 1), ty = min(m, y + n - 1);
    else
      tx = min(n, x + m - 1), ty = min(m, n - x + 1);
    if (tx == n)
      dfs(tx, ty, 4);
    else
      dfs(tx, ty, 2);
  }
  if (d == 2) {
    if (x == 1)
      tx = min(n, y), ty = max(1, y - n + 1);
    else
      tx = min(n, x + m - 1), ty = max(1, m - (n - x + 1) + 1);
    if (tx == n)
      dfs(tx, ty, 3);
    else
      dfs(tx, ty, 1);
  }
  if (d == 3) {
    if (x == n)
      tx = max(1, n - y + 1), ty = max(1, y - n + 1);
    else
      tx = max(1, x - m + 1), ty = max(1, m - x + 1);
    if (tx == 1)
      dfs(tx, ty, 2);
    else
      dfs(tx, ty, 4);
  }
  if (d == 4) {
    if (x == n)
      tx = max(1, n - (m - y + 1) + 1), ty = min(m, y + n - 1);
    else
      tx = max(1, x - m + 1), ty = min(m, x);
    if (tx == 1)
      dfs(tx, ty, 1);
    else
      dfs(tx, ty, 3);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * (n + m); i++) s[i] = i;
  for (int i = 1; i < m; i++) {
    if (!vis[i]) {
      st = 1, dfs(1, i, 1);
      ans++;
      st = 2, dfs(1, i, 2);
    }
  }
  for (int i = 1; i < n; i++) {
    if (!vis[id(i, m)]) {
      st = 1, dfs(i, m, 2);
      st = 2, dfs(i, m, 3);
      ans++;
    }
  }
  for (int i = 2; i <= m; i++) {
    if (!vis[id(n, i)]) {
      st = 1, dfs(n, i, 3);
      ans++;
      st = 2, dfs(n, i, 4);
    }
  }
  for (int i = 2; i <= n; i++) {
    if (!vis[id(i, 1)]) {
      st = 1, dfs(i, 1, 1);
      ans++;
      st = 2, dfs(i, 1, 4);
    }
  }
  printf("%d", ans);
  return 0;
}
