#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 2007;
const int inf = 1e9 + 7;
const double pi = acos(-1);
int n, m;
int mod;
bool check[N][2];
pair<int, int> getUpLeft(int i) {
  if (n > m) {
    if (i >= m) return make_pair(i - m + 1, 0);
  }
  int j = 1;
  j += i - 1;
  int k = (m - j) % mod;
  if (k < mod / 2) {
    return make_pair(1 + k, 1);
  } else {
    return make_pair(n - (k - mod / 2), 0);
  }
}
pair<int, int> getDownLeft(int i) {
  if (n > m) {
    if (i <= n - m + 1) return make_pair(i + m - 1, 1);
  }
  int j = 1 + n - i;
  int k = (m - j) % mod;
  if (k < mod / 2) {
    return make_pair(n - k, 0);
  } else {
    return make_pair(1 + (k - mod / 2), 1);
  }
}
pair<int, int> getUpRight(int i) {
  pair<int, int> tmp = getDownLeft(n + 1 - i);
  return make_pair(n + 1 - tmp.first, 1 - tmp.second);
}
pair<int, int> getDownRight(int i) {
  pair<int, int> tmp = getUpLeft(n + 1 - i);
  return make_pair(n + 1 - tmp.first, 1 - tmp.second);
}
void solve() {
  cin >> n >> m;
  if (n == m) {
    cout << n << "\n";
    return;
  }
  mod = 2 * n - 2;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int cur = i, dir = 0;
    if (i == 1) dir = 1;
    if (!check[i][0] && !check[i][1]) {
      ans++;
      while (!check[cur][dir]) {
        check[cur][dir] = 1;
        pair<int, int> lef;
        if (dir == 0) {
          lef = getUpLeft(cur);
        } else {
          lef = getDownLeft(cur);
        }
        if (lef.first == 1)
          dir = 1;
        else if (lef.first == n)
          dir = 0;
        else
          dir = lef.second;
        pair<int, int> now;
        if (dir == 0) {
          now = getUpRight(lef.first);
        } else {
          now = getDownRight(lef.first);
        }
        cur = now.first;
        dir = now.second;
        if (cur == 1) dir = 1;
        if (cur == n) dir = 0;
      }
    }
  }
  cout << ans;
}
int main() {
  int T = 1;
  for (int i = 1; i <= T; i++) solve();
}
