#include <stdio.h>

int gcd(int a, int b) {
    int tmp;

    while (b > 0) {
        tmp = a % b;
        a = b;
        b = tmp;
    }

    return a;
}

int main() {
    int n, m;

    freopen("cinema.in", "r", stdin);
    freopen("cinema.out", "w", stdout);

    scanf("%d %d", &n, &m);
    printf("%d\n", gcd(n - 1, m - 1) + 1);
    return 0;
}
