#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<pair<int, int> > T;
int n, m;
int f(int x, int y) {
  if (x == 0) return y + 1;
  if (x == n - 1) return m + y + 1;
  if (y == 0) return m + m + x;
  if (y == m - 1) return m + m + n - 1 + x;
}
int flag[4000000 + 5];
void dfs(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m) return;
  if (flag[f(x, y)]) return;
  flag[f(x, y)] = 1;
  dfs(x + m - 1 - y, m - 1);
  dfs(n - 1, y + n - 1 - x);
  dfs(x - y, 0);
  dfs(0, y - x);
  dfs(0, y + x);
  dfs(x - (m - 1 - y), m - 1);
  dfs(x + y, 0);
  dfs(n - 1, y - (n - 1 - x));
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) T.push_back(pair<int, int>(i, 0));
  for (int i = 0; i < n; i++) T.push_back(pair<int, int>(i, m - 1));
  for (int i = 1; i + 1 < m; i++) T.push_back(pair<int, int>(0, i));
  for (int i = 1; i + 1 < m; i++) T.push_back(pair<int, int>(n - 1, i));
  int ans = 0;
  for (int i = 0; i < T.size(); i++) {
    int x = T[i].first, y = T[i].second;
    if (flag[f(x, y)]) continue;
    ans++;
    dfs(x, y);
  }
  cout << ans << endl;
  return 0;
}
