#include <bits/stdc++.h>
using namespace std;
long gcd(long a, long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long n, m;
  cin >> n >> m;
  cout << gcd(n - 1, m - 1) + 1 << endl;
  return 0;
}
