#include <bits/stdc++.h>
using namespace std;
const int N = 2200000;
int chk[N];
int main() {
  ios_base::sync_with_stdio(0);
  int cnt = 0, n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    if (!chk[i]) {
      for (int j = i;
           (j < n && chk[j] < 2) || (j >= n && chk[n + n - 2 - j] < 2);
           j = (j + m + m - 2) % (n + n - 2)) {
        if (j < n)
          chk[j]++;
        else
          chk[n + n - 2 - j]++;
      }
      cnt++;
    }
  cout << cnt << endl;
  return 0;
}
