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