#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
bool ltrd[2000001];
bool rtld[2000001];
bool traversed[1000000];
void mark(int xx) {
  if (traversed[xx]) {
    return;
  }
  ++cnt;
  for (int dd = 0; dd < 2; ++dd) {
    int xdir = (dd == 0) ? 1 : -1;
    int ydir = 1;
    int x = xx;
    int y = 0;
    while (true) {
      if (y == 0) {
        traversed[x] = true;
      }
      bool& bref = (xdir == ydir) ? ltrd[x - y + m - 1] : rtld[x + y];
      if (bref) break;
      bref = true;
      int xdist = (xdir == 1) ? (n - x - 1) : x;
      int ydist = (ydir == 1) ? (m - y - 1) : y;
      int run = min(xdist, ydist);
      x += xdir * run;
      y += ydir * run;
      if (xdist == ydist) {
        xdir = -xdir;
        ydir = -ydir;
      } else if (xdist < ydist) {
        xdir = -xdir;
      } else {
        ydir = -ydir;
      }
    }
  }
}
int main() {
  int a, b;
  cin >> a >> b;
  n = max(a, b);
  m = min(a, b);
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    traversed[i] = false;
  }
  for (int i = 0; i < n; ++i) {
    mark(i);
  }
  cout << cnt << endl;
  return 0;
}
