#include <bits/stdc++.h>
using namespace std;
int n, m;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  scanf("%d%d", &n, &m);
  int x = gcd(n - 1, m - 1);
  cout << (x + 1) << "\n";
  return 0;
}
