#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a, b;

int main() {                       
    freopen("mcd.in", "r", stdin);
    freopen("mcd.out", "w", stdout);
    scanf("%d%d", &a, &b);
    int ans = 1;
    for (int i = 1; (ll)i*i <= a; ++i) {
        if (a % i != 0) continue;
        int j = a/i;
        if (b % i == 0) ans = max(ans, i);
        if (b % j == 0) ans = max(ans, j);
    }
    printf("%d\n", ans);
    return 0;
}