#include <bits/stdc++.h>
using namespace std;
int fa[6000000], n, m;
int get(int x) {
  if (fa[x] == x) return x;
  return fa[x] = get(fa[x]);
}
void merge(int a, int b) { fa[get(b)] = get(a); }
int main() {
  for (int i = 0; i < 6000000; i++) fa[i] = i;
  cin >> n >> m;
  int MAX_C = n + m - 3;
  for (int i = 2; i <= n - 1; i++) {
    int x = i - 1, y = n - i + MAX_C;
    merge(x, y);
  }
  for (int i = 2; i <= n - 1; i++) {
    int x = m - 2 + i, y = n + m - i - 1 + MAX_C;
    merge(x, y);
  }
  for (int i = 2; i <= m - 1; i++) {
    int x = i - 1, y = n - 2 + i + MAX_C;
    merge(x, y);
  }
  for (int i = 2; i <= m - 1; i++) {
    int x = n - 2 + i, y = i - 1 + MAX_C;
    merge(x, y);
  }
  int root = 0;
  for (int i = 1; i <= 2 * MAX_C; i++)
    if (get(i) == i) root++;
  cout << root;
  return 0;
}
