#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int vis[N], n, m;
void dfs(int x, int y, int dx, int dy) {
  if (y == 1) vis[x] = true;
  if (y == 1 || y == m) dy *= -1;
  if (x == 1 || x == n) dx *= -1;
  int r;
  if (dx > 0 && dy > 0) r = min(n - x, m - y);
  if (dx > 0 && dy < 0) r = min(n - x, y - 1);
  if (dx < 0 && dy > 0) r = min(x - 1, m - y);
  if (dx < 0 && dy < 0) r = min(x - 1, y - 1);
  if (y + dy * r == 1 && vis[x + dx * r]) return;
  dfs(x + dx * r, y + dy * r, dx, dy);
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      if (i > 1) dfs(i, 1, +1, -1);
      if (i < n) dfs(i, 1, -1, -1);
      ++ans;
    }
  cout << ans << endl;
}
