import std.stdio;
import std.conv;
import std.string;
import std.numeric;

void main() {
    auto nm = readln.chomp.split.to!(ulong[]);
    auto n = nm[0];
    auto m = nm[1];

    ulong div = m / n;
    ulong mod = m % n;

    if (mod == 0) {
        div.writeln;
        return;
    }

    if (div % mod) {
        mod.writeln;
        return;
    }

    gcd(div, mod).writeln;
}
