#include <bits/stdc++.h>
using namespace std;
const int c = 1000100;
int n, m;
int a[c];
int ans;
int k, p, d;
void go(int i, int b) {
  if (a[i]) return;
  a[i] = 1;
  k = (m - 1) << 1;
  int nb = b;
  p = i;
  while (k) {
    if (b > 0)
      d = min(k, n - p);
    else
      d = min(k, p - 1);
    p += d * b;
    if (d < k) b = -b;
    k -= d;
  }
  go(p, b);
  k = (m - 1) << 1;
  p = i;
  b = -nb;
  while (k) {
    if (b > 0)
      d = min(k, n - p);
    else
      d = min(k, p - 1);
    p += d * b;
    if (d < k) b = -b;
    k -= d;
  }
  go(p, b);
}
int main() {
  scanf("%d%d", &n, &m);
  ans = 0;
  int i;
  for (i = 1; i <= n; ++i)
    if (!a[i]) {
      ++ans;
      go(i, 1);
    }
  printf("%d\n", ans);
  return 0;
}
