#include <bits/stdc++.h>
using namespace std;
template <class T>
T GCD(T a, T b) {
  return (a == 0) ? b : GCD(b % a, a);
}
int main() {
  int n, m;
  cin >> n >> m;
  cout << GCD(n - 1, m - 1) + 1 << endl;
}
