#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e9;
int used[3000000];
void dfs(int i, int j, int x, int y, int n, int m) {
  if (!j) {
    if (used[i]) return;
    used[i]++;
  }
  int len1 = (x < 0 ? i : n - 1 - i);
  int len2 = (y < 0 ? j : m - 1 - j);
  len1 = min(len1, len2);
  int nx = i + x * len1;
  int ny = j + y * len1;
  if (!nx || nx == n - 1) x = -x;
  if (!ny || ny == m - 1) y = -y;
  dfs(nx, ny, x, y, n, m);
}
int proc(int n, int m) {
  memset(used, 0, sizeof used);
  int cnt = 0;
  for (int i = 0; i < (n); i++) {
    if (used[i]) continue;
    cnt++;
    for (int x = -1; x < 2; x += 2)
      for (int y = -1; y < 2; y += 2) {
        used[i] = 0;
        dfs(i, 0, x, y, n, m);
      }
  }
  return cnt;
}
int main() {
  int n, m;
  cin >> n >> m;
  cout << max(proc(n, m), proc(m, n));
}
