#include <bits/stdc++.h>
using namespace std;
int NOD(int A, int B) {
  while (A && B)
    if (A > B)
      A %= B;
    else
      B %= A;
  return A + B;
}
int main() {
  int N, M;
  cin >> N >> M;
  cout << NOD(N - 1, M - 1) + 1;
  return 0;
}
