#include <bits/stdc++.h>
using namespace std;
int f1[1000001], f2[1000001], up[1000001], down[1000001], d1[1000001],
    d2[1000001], up_[1000001], down_[1000001];
bool visited[1000001][3];
int main() {
  int n_, m_;
  cin >> n_ >> m_;
  int n = min(n_, m_);
  int m = max(n_, m_);
  if (m == n) {
    cout << n;
    return 0;
  }
  if (n == 1) {
    cout << m;
    return 0;
  }
  f1[0] = 0;
  f2[0] = n - 1;
  d1[0] = 1;
  d2[0] = -1;
  int up1 = 1;
  int up2 = -1;
  for (int i = 1; i <= m; i++) {
    if (up1 + f1[i - 1] < 0) {
      up1 = 1;
      d1[i] = up1;
      f1[i] = 1;
    } else if (up1 + f1[i - 1] >= n) {
      up1 = -1;
      f1[i] = n - 2;
      d1[i] = up1;
    } else {
      f1[i] = up1 + f1[i - 1];
      d1[i] = up1;
    }
    if (up2 + f2[i - 1] < 0) {
      up2 = 1;
      f2[i] = 1;
      d2[i] = up2;
    } else if (up2 + f2[i - 1] >= n) {
      up2 = -1;
      f2[i] = n - 2;
      d2[i] = up2;
    } else {
      f2[i] = up2 + f2[i - 1];
      d2[i] = up2;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) visited[i][j] = false;
  for (int i = 1; i < n - 1; i++) {
    int del = i;
    {
      down[i] = f1[m - del - 1];
      down_[i] = d1[m - del - 1];
    }
    del = (n - 1) - i;
    {
      up[i] = f2[m - del - 1];
      up_[i] = d2[m - del - 1];
    }
  }
  down[n - 1] = f2[m - 1];
  up[0] = f1[m - 1];
  down_[n - 1] = d2[m - 1];
  up_[0] = d1[m - 1];
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (!visited[i][0] && !visited[i][2]) {
      ans++;
      int temp;
      int q = down[i];
      int q_ = down_[i];
      if (i != 0) {
        if (q == 0 || q == n - 1) goto mark;
        visited[i][0] = true;
        temp = q;
        q = (((q_) == -1) ? (down[(q)]) : up[(q)]);
        q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
        if (q == 0 || q == n - 1) {
          visited[q][((q_) + 1)] = true;
          goto mark;
        }
        while (!visited[q][((q_) + 1)]) {
          visited[q][((q_) + 1)] = true;
          temp = q;
          q = (((q_) == -1) ? (down[(temp)]) : up[(temp)]);
          q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
          if (q == 0 || q == n - 1) break;
          temp = q;
          q = (((q_) == -1) ? (down[(temp)]) : up[(temp)]);
          q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
          if (q == 0 || q == n - 1) {
            visited[q][((q_) + 1)] = true;
            break;
          }
        }
      }
    mark:
      q = 0;
      if (q != n - 1) {
        q = up[i];
        q_ = up_[i];
        temp = q;
        if (q == 0 || q == n - 1) {
          continue;
        }
        visited[i][2] = true;
        q = (((q_) == -1) ? (down[(q)]) : up[(q)]);
        q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
        if (q == 0 || q == n - 1) {
          visited[q][((q_) + 1)] = true;
          continue;
        }
        while (!visited[q][((q_) + 1)]) {
          visited[q][((q_) + 1)] = true;
          temp = q;
          q = (((q_) == -1) ? (down[(temp)]) : up[(temp)]);
          q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
          if (q == 0 || q == n - 1) break;
          temp = q;
          q = (((q_) == -1) ? (down[(temp)]) : up[(temp)]);
          q_ = (((q_) == -1) ? (down_[(temp)]) : up_[(temp)]);
          if (q == 0 || q == n - 1) {
            visited[q][((q_) + 1)] = true;
            break;
          }
        }
      }
    }
  cout << ans;
}
