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