#include <iostream>
#include <numeric>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long a, b;
    if (cin >> a >> b) {
        long long g = std::gcd(a, b);

        if (g == 1) {
            cout << -1 << "\n";
            return 0;
        }

        long long smallest_factor = g;
        for (long long i = 2; i * i <= g; ++i) {
            if (g % i == 0) {
                smallest_factor = i;
                break;
            }
        }

        cout << g / smallest_factor << "\n";
    }

    return 0;
}