#include <bits/stdc++.h>
using namespace std;
int in() {
  int a;
  scanf("%llu", &a);
  return a;
}
int ou(int a) {
  printf("%d", a);
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
struct ed {
  int a, b, cost;
};
struct names {
  string name;
  int reyt;
};
const long long INF = 1000000;
vector<int> tobin(long long a) {
  vector<int> A;
  while (a != 0) {
    A.push_back(a % 2);
    a /= 2;
  }
  return A;
}
int main() {
  ou(gcd(in() - 1, in() - 1) + 1);
  return 0;
}
