#include <bits/stdc++.h>
using namespace std;
int jaja[4][1000016];
int jajaB[4];
set<pair<int, int> > ja;
int n, m;
pair<pair<int, int>, pair<int, int> > fila[4 * 1000016];
int ini, fim;
int posx[4], posy[4];
int marca(int x, int y) {
  if (x == 0) {
    if (y == 0) {
      if (jajaB[0]) return 1;
      jajaB[0] = 1;
      return 0;
    } else if (y == m - 1) {
      if (jajaB[1]) return 1;
      jajaB[1] = 1;
      return 0;
    }
  } else if (x == n - 1) {
    if (y == 0) {
      if (jajaB[2]) return 1;
      jajaB[2] = 1;
      return 0;
    } else if (y == m - 1) {
      if (jajaB[3]) return 1;
      jajaB[3] = 1;
      return 0;
    }
  }
  int opa = 0;
  for (int i = 0; i < (int)(4); i++) {
    if (x == posx[i]) {
      if (jaja[i][y]) opa++;
      jaja[i][y] = 1;
    }
    if (y == posy[i]) {
      if (jaja[i][x]) opa++;
      jaja[i][x] = 1;
    }
  }
  return opa;
}
void insere(int x, int y, int dx, int dy) {
  if (marca(x, y)) return;
  fila[fim++] = make_pair(make_pair(x, y), make_pair(dx, dy));
}
void quica(int x, int y, int dx, int dy) {
  ini = fim = 0;
  fila[fim++] = make_pair(make_pair(x, y), make_pair(dx, dy));
  pair<pair<int, int>, pair<int, int> > aux;
  while (ini < fim) {
    aux = fila[ini++];
    x = aux.first.first;
    y = aux.first.second;
    dx = aux.second.first;
    dy = aux.second.second;
    int andax = 0, anday = 0;
    if (dx == 1) {
      andax = (n - 1) - x;
    } else {
      andax = x;
    }
    if (dy == 1) {
      anday = (m - 1) - y;
    } else {
      anday = y;
    }
    int anda = min(andax, anday);
    x += anda * dx;
    y += anda * dy;
    if (andax == anda) dx *= -1;
    if (anday == anda) dy *= -1;
    insere(x, y, dx, dy);
  }
}
int main() {
  cin >> n >> m;
  memset(posx, -1, sizeof(posx));
  memset(posy, -1, sizeof(posy));
  posx[0] = 0;
  posx[1] = n - 1;
  posy[2] = 0;
  posy[3] = m - 1;
  memset(jaja, 0, sizeof(jaja));
  memset(jajaB, 0, sizeof(jajaB));
  ja.clear();
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    int x = 0, y = i;
    if (!marca(x, y)) {
      ans++;
      quica(x, y, 1, 1);
      quica(x, y, 1, -1);
    }
    x = n - 1;
    y = i;
    if (!marca(x, y)) {
      ans++;
      quica(x, y, -1, 1);
      quica(x, y, -1, -1);
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    int x = i, y = 0;
    if (!marca(x, y)) {
      ans++;
      quica(x, y, 1, 1);
      quica(x, y, -1, 1);
    }
    x = i;
    y = m - 1;
    if (!marca(x, y)) {
      ans++;
      quica(x, y, 1, -1);
      quica(x, y, -1, -1);
    }
  }
  cout << ans << endl;
  return 0;
}
