# Thanks for http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759



N, M = list(map(int, input().split()))





def factorize(n):

    fct = []

    b, e = 2, 0

    while b * b <= n:

        while n % b == 0:

            n = n // b

            e = e + 1

        if e > 0:

            fct.append((b, e))

        b, e = b + 1, 0

    if n > 1:

        fct.append((n, 1))

    return fct



def divisorize(fct):

    b, e = fct.pop()

    pre_div = divisorize(fct) if fct else [[]]

    suf_div = [[(b, k)] for k in range(e + 1)]

    return [pre + suf for pre in pre_div for suf in suf_div]



def num(fct):

    a = 1

    for base, exponent in fct:

        a = a * base**exponent

    return a





try:

    fct = factorize(M)

    L   = []

    for div in divisorize(fct):

        L.append(num(div))

except:

    L = [1, M]



L.sort()

L.reverse()



for l in L:

    if l * N <= M and M % l == 0:

        print(l)

        break

def get_prime_factorized(N):

    R = []

    b, e = 2, 0

    while b ** 2 <= N:

        while N % b == 0:

            N  = N // b

            e += 1

        if e > 0:

            R.append([b, e])

        b, e = b + 1, 0

    if N > 1:

        R.append([N, 1])

    return R



def get_list_divisor(N, reverse=True):

    try:

        F = get_prime_factorized(N)

        L = re_func_divisior(F)

        R = []

        for l in L:

            for i, x in enumerate(l):

                if i == 0:

                    r = x

                else:

                    r *= x

            R.append(r)

        R.sort()

        if reverse == True:

            R.reverse()

    except:

        if N == 1:

            R = [1]

        else:

            R = [N]

    return R



def re_func_divisior(F):

    b, e = F.pop()

    P = re_func_divisior(F) if F else [[]]

    Q = [[b ** k] for k in range(e + 1)]

    return [p + q for p in P for q in Q]





N, M = list(map(int, input().split()))



for d in get_list_divisor(M, reverse=True):

    if d * N <= M and M % d == 0:

        print(d)

        break

# Thanks for http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759
N, M = list(map(int, input().split()))


def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


try:
    fct = factorize(M)
    L = []
    for div in divisorize(fct):
        L.append(num(div))
except:
    L = [1, M]
L.sort()
L.reverse()
for l in L:
    if l * N <= M and M % l == 0:
        print(l)
        break

def get_prime_factorized(N):
    R = []
    b, e = 2, 0
    while b**2 <= N:
        while N % b == 0:
            N = N // b
            e += 1
        if e > 0:
            R.append([b, e])
        b, e = b + 1, 0
    if N > 1:
        R.append([N, 1])
    return R


def get_list_divisor(N, reverse=True):
    try:
        F = get_prime_factorized(N)
        L = re_func_divisior(F)
        R = []
        for l in L:
            for i, x in enumerate(l):
                if i == 0:
                    r = x
                else:
                    r *= x
            R.append(r)
        R.sort()
        if reverse == True:
            R.reverse()
    except:
        if N == 1:
            R = [1]
        else:
            R = [N]
    return R


def re_func_divisior(F):
    b, e = F.pop()
    P = re_func_divisior(F) if F else [[]]
    Q = [[b**k] for k in range(e + 1)]
    return [p + q for p in P for q in Q]


N, M = list(map(int, input().split()))
for d in get_list_divisor(M, reverse=True):
    if d * N <= M and M % d == 0:
        print(d)
        break

-# Thanks for http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759 -N, M = list(map(int, input().split())) +def get_prime_factorized(N): +    R = [] +    b, e = 2, 0 +    while b**2 <= N: +        while N % b == 0: +            N = N // b +            e += 1 +        if e > 0: +            R.append([b, e]) +        b, e = b + 1, 0 +    if N > 1: +        R.append([N, 1]) +    return R -def factorize(n): -    fct = [] -    b, e = 2, 0 -    while b * b <= n: -        while n % b == 0: -            n = n // b -            e = e + 1 -        if e > 0: -            fct.append((b, e)) -        b, e = b + 1, 0 -    if n > 1: -        fct.append((n, 1)) -    return fct +def get_list_divisor(N, reverse=True): +    try: +        F = get_prime_factorized(N) +        L = re_func_divisior(F) +        R = [] +        for l in L: +            for i, x in enumerate(l): +                if i == 0: +                    r = x +                else: +                    r *= x +            R.append(r) +        R.sort() +        if reverse == True: +            R.reverse() +    except: +        if N == 1: +            R = [1] +        else: +            R = [N] +    return R -def divisorize(fct): -    b, e = fct.pop() -    pre_div = divisorize(fct) if fct else [[]] -    suf_div = [[(b, k)] for k in range(e + 1)] -    return [pre + suf for pre in pre_div for suf in suf_div] +def re_func_divisior(F): +    b, e = F.pop() +    P = re_func_divisior(F) if F else [[]] +    Q = [[b**k] for k in range(e + 1)] +    return [p + q for p in P for q in Q] -def num(fct): -    a = 1 -    for base, exponent in fct: -        a = a * base**exponent -    return a - - -try: -    fct = factorize(M) -    L = [] -    for div in divisorize(fct): -        L.append(num(div)) -except: -    L = [1, M] -L.sort() -L.reverse() -for l in L: -    if l * N <= M and M % l == 0: -        print(l) +N, M = list(map(int, input().split())) +for d in get_list_divisor(M, reverse=True): +    if d * N <= M and M % d == 0: +        print(d)