#include <bits/stdc++.h>
using namespace std;
int n, m;
int u[1000005];
int chk_and_set(int x) {
  if (x < n)
    return u[x]++ == 0;
  else
    return u[2 * n - 2 - x]++ == 0;
}
int getnext(int x) { return (x + 2 * (m - 1)) % (2 * n - 2); }
int getprev(int x) { return (x + 2 * n - 2 - 2 * (m - 1)) % (2 * n - 2); }
int main(void) {
  int cnt = 0;
  scanf("%d%d", &n, &m);
  if (m > n) swap(n, m);
  for (int i = 0; i < n; i++) {
    if (!u[i]) {
      ++cnt;
      int j = i;
      while (chk_and_set(j)) j = getnext(j);
      u[i] = 0;
      j = i;
      while (chk_and_set(j)) j = getprev(j);
    }
  }
  printf("%d\n", cnt);
  return 0;
}
