def divisor(n):

    i = 1

    res = []

    for i in range(1, int(n**.5) + 1):

        if n%i == 0:

            res.append(i)

            if n//i not in res:

                res.append(n//i)

    res.sort()

    return res



def main():

    n, m = list(map(int, input().split()))

    md = divisor(m)

    ans = 0

    for i in md:

        if (m - n*i)%i == 0 and (m - n*i) >= 0:

            ans = i

        else:

            break

    print(ans)



if __name__ == '__main__':

    main()
def divisor(n):

    i = 1

    res = []

    for i in range(1, int(n**.5) + 1):

        if n%i == 0:

            res.append(i)

            if n//i not in res:

                res.append(n//i)

    res.sort(reverse=True)

    return res



def main():

    n, m = list(map(int, input().split()))

    md = divisor(m)

    ans = 0

    for i in md:

        if i*n <= m:

            print(i)

            exit()



if __name__ == '__main__':

    main()
def divisor(n):
    i = 1
    res = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            res.append(i)
            if n // i not in res:
                res.append(n // i)
    res.sort()
    return res


def main():
    n, m = list(map(int, input().split()))
    md = divisor(m)
    ans = 0
    for i in md:
        if (m - n * i) % i == 0 and (m - n * i) >= 0:
            ans = i
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()

def divisor(n):
    i = 1
    res = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            res.append(i)
            if n // i not in res:
                res.append(n // i)
    res.sort(reverse=True)
    return res


def main():
    n, m = list(map(int, input().split()))
    md = divisor(m)
    ans = 0
    for i in md:
        if i * n <= m:
            print(i)
            exit()


if __name__ == "__main__":
    main()

-    res.sort() +    res.sort(reverse=True) -        if (m - n * i) % i == 0 and (m - n * i) >= 0: -            ans = i -        else: -            break -    print(ans) +        if i * n <= m: +            print(i) +            exit()