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