#include <bits/stdc++.h>
int n, m, cnt;
struct node {
  node *belong;
  node *get() { return belong ? (belong = belong->get()) : this; }
} V[1000005];
void merge(node &a, node &b) {
  node *x = a.get(), *y = b.get();
  if (x == y) return;
  x->belong = y;
  cnt--;
}
inline int calc(int x) {
  x = (x % (2 * (m - 1)) + 2 * (m - 1)) % (2 * (m - 1));
  return x <= m - 1 ? x : 2 * (m - 1) - x;
}
int main() {
  scanf("%d%d", &n, &m);
  cnt = m;
  for (int j = 0; j < m; j++)
    merge(V[j], V[calc(j + (n - 1) * 2)]),
        merge(V[j], V[calc(j - (n - 1) * 2)]);
  printf("%d\n", cnt);
}
