#include <bits/stdc++.h>
using namespace std;
int f[1000006][2];
int b[1000006];
void dfs(int x) {
  b[x] = 1;
  if (b[f[x][0]] == 0) dfs(f[x][0]);
  if (b[f[x][1]] == 0) dfs(f[x][1]);
}
int main() {
  int i, j, k, n, m, kk, ans;
  while (scanf("%d%d", &n, &m) != EOF) {
    if (n > m) {
      k = n;
      n = m;
      m = k;
    }
    memset(f, 0, sizeof(f));
    for (i = 0; i < n; i++) {
      k = i + m * 2 - 2;
      kk = k % (2 * n - 2);
      {
        if (kk <= n - 1) {
          f[i][0] = kk;
        } else {
          f[i][0] = 2 * n - 2 - kk;
        }
      }
      k = i - m * 2 + 2;
      kk = (k % (2 * n - 2) + (2 * n - 2)) % (2 * n - 2);
      {
        if (kk <= n - 1) {
          f[i][1] = kk;
        } else {
          f[i][1] = 2 * n - 2 - kk;
        }
      }
    }
    memset(b, 0, sizeof(b));
    ans = 0;
    for (i = 0; i < n; i++) {
      if (b[i] == 1) continue;
      ans++;
      k = i;
      dfs(k);
    }
    printf("%d\n", ans);
  }
  return 0;
}
