#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  scanf("%d%d", &m, &n);
  int cnt = 0;
  static bool checked[4][4][1000000];
  for (int side = 0; side < (4); side++)
    for (int t = 0; t < (side % 2 == 0 ? n : m); t++) {
      bool ok = true;
      for (int dir = 0; dir < (4); dir++)
        if (checked[dir][side][t]) {
          ok = false;
          break;
        }
      if (!ok) continue;
      cnt++;
      const int tmp1 = side, tmp2 = t;
      int dir = 0;
      while (!checked[dir][side][t]) {
        checked[dir][side][t] = true;
        if (side == 0) {
          if (dir == 0)
            dir = 3;
          else if (dir == 1)
            dir = 2;
          else if (dir == 2) {
            if (t < m)
              side = 1;
            else
              side = 2, t = t - m + 1;
          } else {
            if (n - t - 1 < m)
              side = 3, t = n - t - 1;
            else
              side = 2, t = t + m - 1;
          }
        } else if (side == 1) {
          if (dir == 0) {
            if (t < n)
              side = 0;
            else
              side = 3, t = t - n + 1;
          } else if (dir == 1)
            dir = 0;
          else if (dir == 2)
            dir = 3;
          else {
            if (m - t - 1 < n)
              side = 2, t = m - t - 1;
            else
              side = 3, t = t + n - 1;
          }
        } else if (side == 2) {
          if (dir == 0) {
            if (n - t - 1 < m)
              side = 3, t = m - (n - t - 1) - 1;
            else
              side = 0, t = t + m - 1;
          } else if (dir == 1) {
            if (t < m)
              side = 1, t = m - t - 1;
            else
              side = 0, t = t - m + 1;
          } else if (dir == 2)
            dir = 1;
          else
            dir = 0;
        } else {
          if (dir == 0)
            dir = 1;
          else if (dir == 1) {
            if (t < n)
              side = 0, t = n - t - 1;
            else
              side = 1, t = t - n + 1;
          } else if (dir == 2) {
            if (m - t - 1 < n)
              side = 2, t = n - (m - t - 1) - 1;
            else
              side = 1, t = t + n - 1;
          } else
            dir = 2;
        }
      }
      side = tmp1, t = tmp2;
    }
  printf("%d\n", cnt);
  return 0;
}
