#include <bits/stdc++.h>
using namespace std;
bool vis[1000001];
int n, m;
int xx[] = {1, 1, -1, -1};
int yy[] = {-1, 1, 1, -1};
void next(int &x, int &y, int &dir) {
  if (dir == 0) {
    if (n - x - 1 < y) {
      y += (n - x - 1) * yy[dir];
      x += (n - x - 1) * xx[dir];
      dir = 3;
    } else {
      x += y * xx[dir];
      y += y * yy[dir];
      dir = 1;
    }
  } else if (dir == 1) {
    if (n - x - 1 < m - y - 1) {
      y += (n - x - 1) * yy[dir];
      x = n - 1;
      dir = 2;
    } else {
      x += (m - y - 1) * xx[dir];
      y = m - 1;
      dir = 0;
    }
  } else if (dir == 2) {
    if (x < m - y - 1) {
      y += x * yy[dir];
      x += x * xx[dir];
      dir = 1;
    } else {
      x += (m - y - 1) * xx[dir];
      y += (m - y - 1) * yy[dir];
      dir = 3;
    }
  } else if (dir == 3) {
    if (x < y) {
      y += x * yy[dir];
      x += x * xx[dir];
      dir = 0;
    } else {
      x += y * xx[dir];
      y += y * yy[dir];
      dir = 2;
    }
  }
}
void dfs(int x, int y, int dir) {
  if (x == 0) {
    if (vis[y]) return;
    vis[y] = true;
  }
  next(x, y, dir);
  dfs(x, y, dir);
}
int main() {
  int mark = 1, r = 0;
  scanf("%d %d", &n, &m);
  if (n == m) {
    printf("%d\n", n);
    return 0;
  }
  for (int i = (0), _i = (m); i < _i; ++i) {
    if (!vis[i]) {
      dfs(0, i, 0);
      vis[i] = false;
      dfs(0, i, 1);
      r++;
    }
  }
  printf("%d\n", r);
}
