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