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