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