#include <bits/stdc++.h>
using namespace std;
const int INFI = (1 << 30);
const long long INFL = (1LL << 62);
const double eps = 1e-7;
const long double pi = acos(-1.0);
const int MAXN = 1000001;
bool vis[MAXN][4];
int main() {
  int n, m;
  cin >> n >> m;
  int sl = 0;
  for (int cs = 0; cs < 4; cs++) {
    int border;
    if (cs == 0 || cs == 2)
      border = m;
    else
      border = n;
    for (int i = 1; i <= border; i++) {
      if (!vis[i][cs]) {
        vis[i][cs] = 1;
        sl++;
        queue<pair<int, int> > q;
        q.push(make_pair(i, cs));
        while (!q.empty()) {
          int pz = q.front().first;
          int cas = q.front().second;
          int newcs, newpz;
          q.pop();
          switch (cas) {
            case 0:
              if (n < pz) {
                newcs = 2;
                newpz = pz - n + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 3;
                newpz = pz;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              if (n < m - pz + 1) {
                newcs = 2;
                newpz = pz + n - 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 1;
                newpz = m - pz + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              break;
            case 1:
              if (m < pz) {
                newcs = 3;
                newpz = pz - m + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 0;
                newpz = m - pz + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              if (m < n - pz + 1) {
                newcs = 3;
                newpz = pz + m - 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 2;
                newpz = m - (n - pz);
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              break;
            case 2:
              if (n < pz) {
                newcs = 0;
                newpz = pz - n + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 3;
                newpz = n - pz + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              if (n < m - pz + 1) {
                newcs = 0;
                newpz = pz + n - 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 1;
                newpz = n - (m - pz);
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              break;
            case 3:
              if (m < pz) {
                newcs = 1;
                newpz = pz - m + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 0;
                newpz = pz;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              if (m < n - pz + 1) {
                newcs = 1;
                newpz = pz + m - 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              } else {
                newcs = 2;
                newpz = n - pz + 1;
                if (!vis[newpz][newcs]) {
                  vis[newpz][newcs] = 1;
                  q.push(make_pair(newpz, newcs));
                }
              }
              break;
          }
        }
      }
    }
  }
  cout << sl;
  return 0;
}
