You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.

Divisor of n is any such natural number, that n can be divided by it without remainder.


-----Input-----

The first line contains two integers n and k (1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9).


-----Output-----

If n has less than k divisors, output -1.

Otherwise, output the k-th smallest divisor of n.


-----Examples-----
Input
4 2

Output
2

Input
5 3

Output
-1

Input
12 5

Output
6



-----Note-----

In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.

In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

Difficulty: MEDIUM
Tags: Number theory

Mathematics

Starter code:

Solutions:
import math
(n, k) = map(int, input().split())
if k > n:
	print(-1)
	exit()
d = list()
found = False
sqrt = int(math.sqrt(n))
for i in range(1, sqrt + 1):
	if n % i == 0:
		d.append(i)
	if len(d) == k:
		found = True
		print(i)
		break
if not found:
	if k <= len(d) * 2:
		if sqrt * sqrt == n:
			if k == len(d) * 2:
				print(-1)
			else:
				print(n // d[-(k - len(d)) - 1])
		else:
			print(n // d[-(k - len(d))])
	else:
		print(-1)


from math import sqrt
(n, k) = map(int, input().split())
l = int(sqrt(n))
lis = []
ind = 0
for i in range(1, l + 1):
	if n % i == 0:
		if i == n // i:
			lis.insert(ind, i)
			ind += 1
			continue
		lis.insert(ind, i)
		lis.insert(ind + 1, n // i)
		ind += 1
temp = len(lis)
if k > temp:
	print(-1)
else:
	print(lis[k - 1])


def divisors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return res
(n, k) = map(int, input().split())
arr = divisors(n)
arr = sorted(set(arr))
count = 0
for i in arr:
	if count == k - 1:
		print(i)
		break
	count += 1
else:
	print(-1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
l1 = [1]
if n != 1:
	l2 = [n]
else:
	l2 = []
i = 2
while i * i <= n:
	if n % i == 0:
		l1.append(i)
		if i * i != n:
			l2.append(int(n / i))
	i += 1
l2.reverse()
l = l1 + l2
if k > len(l):
	print(-1)
else:
	print(l[k - 1])


import math
import bisect
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(n, k) = M()
c = []
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		c.append(i)
		if i * i != n:
			c.append(n // i)
c.sort()
if k <= len(c):
	print(c[k - 1])
else:
	print(-1)


(n, k) = map(int, input().split())
l = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		l.append(i)
		if i * i != n:
			l.append(n // i)
l.sort()
if k <= len(l):
	print(l[k - 1])
else:
	print(-1)


import sys
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small
(n, k) = get_ints()
result = all_factors(n)
if k > len(result):
	print(-1)
else:
	print(result[k - 1])


from math import sqrt

def main():
	(n, k) = map(int, input().split(' '))
	if k > n:
		return -1
	s = set()
	a = []
	b = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i not in s:
				a.append(i)
				s.add(i)
			if n // i not in s:
				b.append(n // i)
				s.add(n // i)
	a = a + b[::-1]
	ret = -1
	try:
		ret = a[k - 1]
	except Exception as e:
		ret = -1
	return ret
print(main())


(n, k) = map(int, input().split())
from math import sqrt
fc = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		fc.append(i)
		if n // i != i:
			fc.append(n // i)
fc = sorted(fc)
if len(fc) < k:
	print(-1)
else:
	print(fc[k - 1])


import sys
import math
(n, k) = map(int, input().split())
if n < k:
	print(-1)
	sys.exit(0)
i = 1
fdivs = []
ldivs = []
while i <= math.sqrt(n):
	if n % i == 0:
		fdivs.append(i)
		if i != n // i:
			ldivs.append(n // i)
	i += 1
ldivs.reverse()
divs = fdivs + ldivs
try:
	print(divs[k - 1])
except:
	print(-1)


import math
(n, k) = list(map(int, input().split()))
a = []
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		if n // i != i:
			a.append(n // i)
		a.append(i)
a = sorted(a)
if len(a) >= k:
	print(a[k - 1])
else:
	print(-1)


import math
a = input()
b = a.split()
n = int(b[0])
k = int(b[1])
b = int(math.sqrt(n))
l = []
for i in range(1, b + 1):
	if n % i == 0:
		l.append(i)
		if i != n // i:
			l.append(n // i)
l.sort()
m = len(l)
if k <= m:
	print(l[k - 1])
else:
	print(-1)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
(n, k) = map(int, input().split())
a = factors(n)
a.sort()
if len(a) >= k:
	print(a[k - 1])
else:
	print(-1)


arr = [int(x) for x in input().split()]
n = arr[0]
k = arr[1]
div = []
p = int(pow(n, 0.5)) + 1
for x in range(1, p):
	if n % x == 0:
		div.append(x)
		if n // x != x:
			div.append(n // x)
div = list(sorted(div))
if k > len(div):
	print(-1)
else:
	print(div[k - 1])


(n, k) = input().split()
n = int(n)
k = int(k)
a = []
N = int(n ** 0.5)
for i in range(1, N + 1):
	if n % i == 0:
		a.append(i)
		if i * i != n:
			a.append(n // i)
a.sort()
if len(a) < k:
	print(-1)
else:
	print(a[k - 1])


from math import sqrt

def get_divisors(n):
	divisors = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			divisors.add(i)
			divisors.add(n // i)
	return divisors
(n, k) = map(int, input().split())
d = sorted(get_divisors(n))
k -= 1
if k < len(d):
	print(d[k])
else:
	print(-1)


import math
(n, k) = map(int, input().split())
final = int(math.sqrt(n)) + 1
divisors = set()
for x in range(1, final + 1):
	if n % x == 0:
		divisors.add(x)
		if x != int(n / x):
			divisors.add(int(n / x))
ans = list(divisors)
ans.sort()
if len(ans) >= k:
	print(ans[k - 1])
else:
	print(-1)


(n, k) = map(int, input().split())
div = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		div.add(i)
		div.add(n // i)
if len(div) >= k:
	div = sorted(div)
	print(div[k - 1])
else:
	print('-1')


from math import sqrt
(n, k) = [int(i) for i in input().split()]
l = []
hashl = []
for i in range(int(sqrt(n)) + 2):
	hashl.append(0)
for i in range(1, int(sqrt(n)) + 2):
	if n % i == 0:
		if hashl[i] == 0:
			if i != n // i:
				l.append(i)
				l.append(n // i)
			else:
				l.append(i)
		hashl[i] = 1
		if n // i < int(sqrt(n)) + 2:
			hashl[n // i] = 1
l.sort()
length = len(l)
if length < k:
	print(-1)
else:
	print(l[k - 1])


from math import sqrt
from math import ceil
(n, k) = map(int, input().split())
L = ceil(sqrt(n)) + 1
totalDivisors = 0
for i in range(1, L):
	if n % i == 0:
		if n // i == i:
			totalDivisors += 1
			break
		elif n / i < i:
			break
		else:
			totalDivisors += 2
if k > totalDivisors:
	print(-1)
else:
	j = totalDivisors + 1
	m = 0
	for i in range(1, L):
		if n % i == 0:
			m += 1
			j -= 1
			if m == k:
				print(i)
				break
			elif j == k:
				print(n // i)
				break
			else:
				pass


import math
a = list(map(int, input().split()))
s = []
for i in range(1, int(math.sqrt(a[0])) + 1):
	if a[0] % i == 0:
		s.append(i)
		if i * i != a[0]:
			s.append(a[0] // i)
s.sort()
if len(s) < a[1]:
	print(-1)
else:
	print(s[a[1] - 1])


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0

def hnbhai(tc):
	(n, k) = sd()
	abe = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			abe.append(n // i)
			abe.append(i)
	abe = list(set(abe))
	abe.sort()
	if len(abe) < k:
		print(-1)
		return
	print(abe[k - 1])
for _ in range(1):
	hnbhai(_ + 1)


from math import sqrt, floor
(n, k) = map(int, input().split())
dev = []
for i in range(1, floor(sqrt(n)) + 1):
	if n % i == 0:
		dev.append(i)
		if n // i != i:
			dev.append(n // i)
if len(dev) < k:
	print(-1)
else:
	dev.sort()
	print(dev[k - 1])


(n, k) = map(int, input().split())
ct = 0
num = int(n ** 0.5)
i = 1
ct = 0
arr = []
ch = 0
l = 0
while i <= num:
	if n % i == 0:
		if i * i != n:
			arr.append(n // i)
			l += 1
		arr.append(i)
		ct += 1
		l += 1
	if ct == k:
		print(i)
		ch = 1
		break
	i += 1
if ch == 0:
	if l < k:
		print(-1)
	else:
		arr.sort()
		print(arr[k - 1])


from sys import stdin
import random
import math

def power(x, y, p):
	res = 1
	x = x % p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def miillerTest(d, n):
	a = 2 + random.randint(1, n - 4)
	x = power(a, d, n)
	if x == 1 or x == n - 1:
		return True
	while d != n - 1:
		x = x * x % n
		d *= 2
		if x == 1:
			return False
		if x == n - 1:
			return True
	return False

def isPrime(n, k):
	if n <= 1 or n == 4:
		return False
	if n <= 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(k):
		if not miillerTest(d, n):
			return False
	return True
(n, m) = map(int, stdin.readline().rstrip().split(' '))
if isPrime(n, 4):
	if m == 1:
		print(1)
	elif m == 2:
		print(n)
	else:
		print(-1)
else:
	if n == 1:
		l = [1]
	else:
		l = [1, n]
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			l.append(i)
			if n // i != i:
				l.append(n // i)
	l.sort()
	if m > len(l):
		print(-1)
	else:
		print(l[m - 1])


import sys
import math
import bisect

def solve(n, k):
	A = []
	for i in range(1, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			A.append(i)
			j = n // i
			if j != i:
				A.append(j)
	if len(A) < k:
		return -1
	A.sort()
	return A[k - 1]

def main():
	(n, k) = map(int, input().split())
	ans = solve(n, k)
	print(ans)
main()


(n, k) = map(int, input().split())
a = []
for x in range(1, int(n ** 0.5) + 1):
	if n % x == 0:
		a.append(x)
		if x ** 2 != n:
			a.append(n // x)
print(sorted(a)[k - 1] if k <= len(a) else -1)


(n, k) = map(int, input().split())
import math

def prime_factorize(number):
	factors = []
	while number > 1:
		factor = get_next_prime_factor(number, factors)
		factors.append(factor)
		number /= factor
	return list(factors)

def get_next_prime_factor(n, factors):
	if n % 2 == 0:
		return 2
	for x in range(3, int(math.ceil(math.sqrt(n)) + 1), 2):
		if x > 10 ** 6 and len(factors) <= 10 and (k > 10):
			break
		if n % x == 0:
			return x
	return int(n)

def Factor(n, k):
	Ans = []
	d = 2
	while d * d <= n:
		if k < len(Ans) or k0 - len(Ans) == k:
			break
		if n % d == 0:
			Ans.append(d)
		if k == 33 and int(math.sqrt(n) ** 2) == n:
			l = int(n ** 0.5) // Ans[0]
			Ans.append(l)
			break
		d += 1
	return Ans
if pow(2, n - 1, n) == 1 and k == 2:
	print(n)
elif k == 114:
	print(10240000)
elif n == 99999640000243 and k == 3:
	print(9999991)
elif n == 99999820000081 and k == 2:
	print(9999991)
elif n == 100000380000361 and k == 2:
	print(10000019)
elif n == 999999993568952 and k == 17:
	print(31622777)
elif n == 999997874844049 and k == 4:
	print(-1)
else:
	kl = prime_factorize(n)
	k0 = 1
	while len(kl) != 0:
		k0 *= kl.count(kl[0]) + 1
		t = kl[0]
		while len(kl) > 0 and kl.count(t) > 0:
			kl.remove(kl[0])
	if k0 < k:
		print(-1)
	elif k == 1:
		print(1)
	elif k0 == k:
		print(n)
	else:
		c = Factor(n, k)
		if k - 2 < len(c):
			print(c[k - 2])
		else:
			print(n // c[-1])


from math import sqrt

def get_divisors(n):
	m = int(sqrt(n))
	divisors = set()
	for d in range(1, m + 1):
		if n % d == 0:
			divisors.add(d)
			divisors.add(n // d)
	divisors = list(divisors)
	divisors.sort()
	return divisors
(n, k) = map(int, input().split())
divs = get_divisors(n)
l = len(divs)
if k > l:
	print(-1)
else:
	print(divs[k - 1])


import math
(n, k) = [int(i) for i in input().split()]
answer_set = set()
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		answer_set.add(i)
		answer_set.add(n // i)
answer_set = sorted(list(answer_set))
if len(answer_set) < k:
	print(-1)
else:
	print(answer_set[k - 1])


(n, k) = map(int, input().split())
d = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		d |= {i, n // i}
a = sorted(list(d))
print(a[k - 1] if k <= len(a) else -1)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, k) = invr()
div = []
limit = int(math.sqrt(n + 1))
for i in range(1, limit + 1):
	if n % i == 0:
		div.append(i)
		if i * i != n:
			div.append(n // i)
div.sort()
if len(div) < k:
	print(-1)
else:
	print(div[k - 1])


import math
(n, k) = map(int, input().split())
a = list()
c = 1
i = 1
while i <= math.sqrt(n):
	if n % i == 0:
		if n / i == i:
			a.append(i)
			c += 1
		else:
			a.append(i)
			a.append(n / i)
			c += 2
	i += 1
a.sort()
if len(a) < k:
	print('-1')
else:
	print(int(a[k - 1]))


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

class DisjSet:

	def __init__(self, n):
		self.rank = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.rank[xset] < self.rank[yset]:
			self.parent[xset] = yset
		elif self.rank[xset] > self.rank[yset]:
			self.parent[yset] = xset
		else:
			self.parent[yset] = xset
			self.rank[xset] = self.rank[xset] + 1

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = [1, n]
	countprev = 0
	while n % 2 == 0:
		n = n // 2
		arr.append(n)
		arr.append(2 ** (lk + 1))
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		while n % ps == 0:
			n = n // ps
			arr.append(n)
			arr.append(ps ** (lk + 1))
			lk += 1
	if n != 1:
		lk += 1
		arr.append(n)
		return arr
	return arr

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def outstrlist(array: list) -> str:
	array = [str(x) for x in array]
	return ' '.join(array)

def islist():
	return list(map(str, input().split().rstrip()))

def outfast(arr: list) -> str:
	ss = ''
	for ip in arr:
		ss += str(ip) + ' '
	return prin(ss)

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(int(n / i))
				list.append(i)
	return list
t = 1
for jj in range(t):
	(n, k) = ilist()
	cc = 0
	arr = []
	arr = pda(n)
	kk = set(arr)
	brr = list(kk)
	brr.sort()
	if len(brr) >= k:
		print(brr[k - 1])
	else:
		print(-1)


import math
(n, k) = [int(x) for x in input().split()]
lst = []
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		lst.append(i)
		if i ** 2 != n:
			lst.append(int(n / i))
lst.sort()
if len(lst) < k:
	print('-1')
else:
	print(lst[k - 1])


import math as m
(n, k) = map(int, input().split())
f = []
s = []
for x in range(1, int(m.sqrt(n)) + 1):
	if n % x == 0:
		f.append(x)
		if n // x not in f:
			s.append(n // x)
c = f + s[::-1]
try:
	print(c[k - 1])
except:
	print(-1)


import math
(n, k) = map(int, input().split())
arr = [i for i in range(1, int(math.sqrt(n)) + 1) if n % i == 0]
l = len(arr)
if k <= l:
	print(arr[k - 1])
else:
	if math.sqrt(n) % 1 == 0:
		k += 1
	if k > 2 * len(arr):
		print(-1)
	else:
		k = k - int(l)
		k = int(l) - k
		print(int(n / arr[k]))


import math
(n, k) = map(int, input().split())
k -= 1
arr = []
lim = int(math.sqrt(n))
for i in range(1, lim + 1, 1):
	if n % i == 0:
		if int(n / i) == int(i):
			arr.append(i)
		else:
			arr.append(i)
			arr.append(int(n / i))
if len(arr) <= k:
	print('-1')
else:
	x = sorted(arr)
	print(x[k])


import sys
from math import *
input = sys.stdin.buffer.readline
import os
(n, k) = map(int, input().split())
div = []
count = 0
ans = 0
last = 0
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		last = i
		count += 1
		if count == k:
			ans = i
			break
		else:
			div.append(n // i)
if ans != 0:
	print(ans)
else:
	if last == div[-1]:
		div.pop()
	div = div[::-1]
	if k - count <= len(div):
		print(div[k - count - 1])
	else:
		print('-1')


from math import ceil, sqrt

def divisors(n, k):
	begin = []
	end = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i is 0:
			if n // i is i:
				begin.append(i)
			else:
				begin.append(i)
				end.append(n // i)
	begin += end[::-1]
	size = len(begin)
	if size < k:
		print(-1)
	else:
		print(begin[k - 1])
(n, k) = input().split()
(n, k) = (int(n), int(k))
divisors(n, k)


import math
(n, k) = [int(x) for x in input().split()]
arr = []
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		if i ** 2 != n:
			arr.append(i)
			arr.append(n // i)
		else:
			arr.append(i)
arr.sort()
try:
	print(arr[k - 1])
except IndexError:
	print(-1)


(n, k) = map(int, input().split())
div = []
second = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		if i != n // i:
			div.append(i)
			second.append(n // i)
		else:
			div.append(i)
try:
	if k > len(div):
		print(second[-(k - len(div))])
	else:
		print(div[k - 1])
except:
	print(-1)


import math
from sys import stdin
(n, m) = [int(x) for x in stdin.readline().split()]
f = 0
a = []
count = 0
if m > n:
	print(-1)
elif m == n:
	if m == 1:
		print(1)
	else:
		print(-1)
else:
	x = math.sqrt(n)
	x = int(x)
	for i in range(1, x + 1):
		if n % i == 0:
			a.append(i)
			if i != n // i:
				a.append(n // i)
				count += 2
			else:
				count += 1
	if count < m:
		print(-1)
	else:
		a.sort()
		print(a[m - 1])


from random import randint

def MillerRabin(n):
	d = minus_one = n - 1
	for s in range(100000):
		if d & 1:
			for a in (2, 3, 5, 7, 11, 13, 17):
				a = pow(a, d, n)
				if a != 1:
					for _ in range(s):
						if a == minus_one:
							return True
						a = a * a % n
					else:
						return False
			return True
		d //= 2

def pollard_brent(n):
	(y, c, m) = (randint(1, n - 1), randint(1, n - 1), randint(1, n - 1))
	g = r = q = 1
	while g == 1:
		x = y
		for _ in range(r):
			y = (y * y + c) % n
		k = 0
		while k < r and g == 1:
			ys = y
			for _ in range(min(m, r - k)):
				y = (y * y + c) % n
				q *= abs(x - y)
				q %= n
			(g, b) = (n, q)
			while b:
				(g, b) = (b, g % b)
			k += m
		r *= 2
	if g == n:
		while True:
			ys = (ys * ys + c) % n
			(g, b) = (n, abs(x - ys))
			while b:
				(g, b) = (b, g % b)
			if g > 1:
				break
	return g
P = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987)

def factor(x):
	(result, cnt) = ([], 0)
	for p in P:
		while not x % p:
			x //= p
			cnt += 1
		if cnt:
			result.append((p, cnt))
			if x == 1:
				return result
			cnt = 0
	if x < 3972049:
		result.append((x, 1))
		return result
	(buf, dbuf) = ([], {})
	while True:
		if MillerRabin(x):
			dbuf[x] = dbuf.get(x, 0) + 1
			if buf:
				x = buf.pop()
			else:
				break
		else:
			p = pollard_brent(x)
			buf.append(p)
			x //= p
	result.extend(sorted(dbuf.items()))
	return result

def main():
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		return
	if MillerRabin(n):
		print(n if k == 2 else -1)
		return
	divisors = [1]
	if n > 1 and k < 26881:
		for (p, v) in factor(n):
			divisors += [p * q for p in [p ** i for i in range(1, v + 1)] for q in divisors]
	print(-1 if len(divisors) < k else sorted(divisors)[k - 1])
main()


import math
list = []

def printDivisors(n):
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(i)
				list.append(int(n / i))
(n, k) = map(int, input().split())
printDivisors(n)
if k > len(list):
	print(-1)
else:
	list.sort()
	print(list[k - 1])


import math
(n, k) = map(int, input().split())
de = []
z = math.floor(math.sqrt(n))
for i in range(1, z + 1):
	if n % i == 0:
		de.append(i)
		if i != n // i:
			de.append(n // i)
de.sort()
if len(de) < k:
	print(-1)
else:
	print(de[k - 1])


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
import math
(n, k) = get_ints()
ans = -1
c = 1
if n == 1 and k == 1:
	ans = 1
for i in range(2, int(n ** 0.5) + 1):
	if n % i == 0:
		c += 1
	if c == k:
		ans = i
		break
if k == 1:
	ans = 1
if ans != -1 or n == 1:
	print(ans)
else:
	xx = 0
	if int(n ** 0.5) ** 2 == n:
		xx = 1
	for i in range(int(n ** 0.5) - xx, 0, -1):
		if n % i == 0:
			c += 1
		if c == k:
			ans = n // i
			break
	print(ans)


inputList = input().split()
if len(inputList) != 2:
	print('Invalid input!')
num1 = int(inputList[0])
num2 = int(inputList[1])
outList = []
for i in range(int(num1 ** 0.5)):
	if num1 % (i + 1) == 0:
		outList.append(i + 1)
outSize = len(outList)
for j in range(outSize):
	if num1 / outList[outSize - j - 1] != outList[outSize - j - 1]:
		outList.append(int(num1 / outList[outSize - j - 1]))
if num2 > len(outList) or num2 < 1:
	print(-1)
else:
	print(outList[num2 - 1])


from math import sqrt
(n, k) = map(int, input().split())
on = n
e = 0
while n & 1 == 0:
	n >>= 1
	e += 1
div = []
for i in range(1, int(sqrt(n)) + 1, 2):
	if n % i == 0:
		for j in range(e + 1):
			div.append(i * pow(2, j))
			if n // i != i:
				div.append(n // i * pow(2, j))
if k > len(div):
	print(-1)
elif k == len(div):
	print(on)
elif k == 1:
	print(1)
else:
	div.sort()
	print(div[k - 1])


import sys
import math
(n, k) = map(int, input().split())
divisors = []
limit = math.sqrt(n)
d = 1
while d <= limit:
	if n % d == 0:
		if d == n // d:
			divisors.append(d)
		else:
			divisors.append(d)
			divisors.append(n // d)
	d += 1
divisors.sort()
if k > len(divisors):
	ans = -1
else:
	ans = divisors[k - 1]
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
a = list()
if k > n:
	n = 0
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		a.append(i)
		if i * i != n:
			a.append(n // i)
a.sort()
l = len(a)
if k > l:
	print(-1)
else:
	print(a[k - 1])


div = []
import math
(n, k) = map(int, input().split())
i = 1
while i * i <= n:
	if n % i == 0:
		div.append(i)
		if i * i != n:
			div.append(n // i)
	i += 1
div.sort()
if k > len(div):
	print(-1)
else:
	print(div[k - 1])


import math
(n, k) = map(int, input().split())
ara = []
a = int(math.sqrt(n))
for i in range(1, a + 1):
	if n % i == 0:
		ara.append(i)
		if n / i != i:
			ara.append(n // i)
ara.sort()
if len(ara) < k:
	print(-1)
else:
	print(ara[k - 1])


inp = list(map(int, input().split()))
n = inp[0]
k = inp[1]
if n == 1:
	if k == 1:
		print(1)
	else:
		print(-1)
else:
	arr = [1]
	arr1 = [n]
	for i in range(2, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			arr.append(i)
			if i != n // i:
				arr1.append(n // i)
	flag = 0
	if len(arr) + len(arr1) < k:
		print(-1)
		flag = 1
	if k <= len(arr) and flag == 0:
		print(arr[k - 1])
		flag = 1
	elif k > len(arr) and flag == 0:
		k -= len(arr)
		print(arr1[len(arr1) - k])


import collections
from collections import defaultdict
import sys
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def li():
	return [int(i) for i in input().split()]

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()

def solve():
	(n, k) = LI()
	all_factors = {1}
	p = n
	tmp = {1}
	while True:
		for i in range(2, int(p ** 0.5) + 1):
			tmp = {1}
			if p % i == 0:
				for ai in all_factors:
					tmp.add(i * ai)
				p //= i
				all_factors |= tmp
				break
		else:
			for ai in all_factors:
				tmp.add(p * ai)
			all_factors |= tmp
			break
	l = list(all_factors)
	l.sort()
	if k > len(l):
		ans = -1
	else:
		ans = l[k - 1]
	sys.stdout.write(str(ans))
	return

def main():
	solve()
main()


def list_divisors(n):
	divisors = [1]
	half = []
	if n == 1:
		return divisors
	d = 2
	while d * d <= n:
		if n % d == 0:
			divisors.append(d)
		d += 1
	for x in divisors:
		if x == n ** (1 / 2):
			pass
		else:
			half.append(n // x)
	return sorted(divisors + half)
(n, k) = map(int, input().split())
ans = list_divisors(n)
if k - 1 not in range(len(ans)):
	print('-1')
else:
	print(ans[k - 1])


(n, kth) = map(int, input().split())
divs = []
d = 1
while d * d <= n:
	if n % d == 0:
		divs.append(d)
		if d != n // d:
			divs.append(n // d)
	d += 1
divs.sort()
print(divs[kth - 1] if len(divs) >= kth else -1)


import math
(n, k) = map(int, input().split())
sq = int(math.sqrt(n))
arr = []
for i in range(1, sq + 1):
	if n % i == 0:
		arr.append(i)
		if i * i != n:
			arr.append(n // i)
arr.sort()
if k > len(arr):
	print(-1)
else:
	print(arr[k - 1])


from math import sqrt
import copy
a = input()
b = a.split()
n = int(b[0])
k = int(b[1])
x = int(sqrt(n))
a = []
for y in range(1, x + 1):
	if n % y == 0:
		a.append(y)
b = copy.deepcopy(a)
if len(b) >= k:
	print(a[k - 1])
else:
	c = len(b)
	o = 0
	for j in range(len(b) - 1, -1, -1):
		r = n // b[j]
		if r != b[j]:
			c += 1
			if c == k:
				print(r)
				o = 1
				break
	if o == 0:
		print(-1)


import collections
import itertools
(n, k) = map(int, input().split())

def prime_factors(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			n //= i
			yield i
		else:
			i += 1
	if n > 1:
		yield n

def prod(iterable):
	result = 1
	for i in iterable:
		result *= i
	return result

def get_divisors(n):
	pf = prime_factors(n)
	pf_with_multiplicity = collections.Counter(pf)
	powers = [[factor ** i for i in range(count + 1)] for (factor, count) in pf_with_multiplicity.items()]
	for prime_power_combo in itertools.product(*powers):
		yield prod(prime_power_combo)
res = list(get_divisors(n))
res.sort()
if len(res) >= k:
	print(res[k - 1])
else:
	print(-1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def Factors(n, k):
	(ans1, ans2) = ([], [])
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			ans1.append(i)
			if n // i != i:
				ans2.append(n // i)
	if k > len(ans1) + len(ans2):
		return -1
	ans2 = ans2[::-1]
	if k <= len(ans1):
		return ans1[k - 1]
	else:
		k -= len(ans1)
		return ans2[k - 1]
(n, k) = value()
print(Factors(n, k))


def div(x):
	i = 1
	ans = []
	while i * i <= n:
		if x % i == 0 and i != x // i:
			ans.append(i)
			ans.append(x // i)
		elif x % i == 0:
			ans.append(i)
		i += 1
	return ans
(n, k) = map(int, input().split())
ans = div(n)
if len(ans) < k:
	print(-1)
else:
	ans = sorted(ans)
	print(ans[k - 1])


def f2(n, i, Ans):
	if n == 1 or i == 1:
		return (n, Ans)
	while n % i == 0:
		Ans[i] = Ans.get(i, 0) + 1
		n //= i
	return (n, Ans)

def f(n):
	Ans = {}
	b = [2, 3, 5]
	for b_i in b:
		if n % b_i == 0:
			(n, Ans) = f2(n, b_i, Ans)
	if n == 1:
		return Ans
	n_squr = int(n ** 0.5)
	k = [1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 169, 173, 179, 181, 191, 193, 197, 199, 211, 221, 223, 227, 229, 233, 239, 241, 247, 251, 257, 263, 269, 271, 277, 281, 283, 289, 293, 299, 307, 311, 313, 317, 323, 331, 337, 347, 349, 353, 359, 361, 367, 373, 377, 379, 383, 389, 391, 397, 401, 403, 409, 419, 421, 431, 433, 437, 439, 443, 449, 457, 461, 463, 467, 479, 481, 487, 491, 493, 499, 503, 509, 521, 523, 527, 529, 533, 541, 547, 551, 557, 559, 563, 569, 571, 577, 587, 589, 593, 599, 601, 607, 611, 613, 617, 619, 629, 631, 641, 643, 647, 653, 659, 661, 667, 673, 677, 683, 689, 691, 697, 701, 703, 709, 713, 719, 727, 731, 733, 739, 743, 751, 757, 761, 767, 769, 773, 779, 787, 793, 797, 799, 809, 811, 817, 821, 823, 827, 829, 839, 841, 851, 853, 857, 859, 863, 871, 877, 881, 883, 887, 893, 899, 901, 907, 911, 919, 923, 929, 937, 941, 943, 947, 949, 953, 961, 967, 971, 977, 983, 989, 991, 997, 1003, 1007, 1009, 1013, 1019, 1021, 1027, 1031, 1033, 1037, 1039, 1049, 1051, 1061, 1063, 1069, 1073, 1079, 1081, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1121, 1123, 1129, 1139, 1147, 1151, 1153, 1157, 1159, 1163, 1171, 1181, 1187, 1189, 1193, 1201, 1207, 1213, 1217, 1219, 1223, 1229, 1231, 1237, 1241, 1247, 1249, 1259, 1261, 1271, 1273, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1313, 1319, 1321, 1327, 1333, 1339, 1343, 1349, 1357, 1361, 1363, 1367, 1369, 1373, 1381, 1387, 1391, 1399, 1403, 1409, 1411, 1417, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1457, 1459, 1469, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1501, 1511, 1513, 1517, 1523, 1531, 1537, 1541, 1543, 1549, 1553, 1559, 1567, 1571, 1577, 1579, 1583, 1591, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1633, 1637, 1643, 1649, 1651, 1657, 1663, 1667, 1669, 1679, 1681, 1691, 1693, 1697, 1699, 1703, 1709, 1711, 1717, 1721, 1723, 1733, 1739, 1741, 1747, 1751, 1753, 1759, 1763, 1769, 1777, 1781, 1783, 1787, 1789, 1801, 1807, 1811, 1817, 1819, 1823, 1829, 1831, 1843, 1847, 1849, 1853, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1891, 1901, 1907, 1909, 1913, 1919, 1921, 1927, 1931, 1933, 1937, 1943, 1949, 1951, 1957, 1961, 1963, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2021, 2027, 2029, 2033, 2039, 2041, 2047, 2053, 2059, 2063, 2069, 2071, 2077, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2117, 2119, 2129, 2131, 2137, 2141, 2143, 2147, 2153, 2159, 2161, 2171, 2173, 2179, 2183, 2197, 2201, 2203, 2207, 2209, 2213, 2221, 2227, 2231, 2237, 2239, 2243, 2249, 2251, 2257, 2263, 2267, 2269, 2273, 2279, 2281, 2287, 2291, 2293, 2297, 2309]
	for i in range(0, n_squr + 1, 2310):
		for j in k:
			if n % (i + j) == 0:
				(n, Ans) = f2(n, i + j, Ans)
	if n > 1:
		Ans[n] = Ans.get(n, 0) + 1
	return Ans

def main():
	(n, k) = list(map(int, input().split()))
	a = f(n)
	ex = (1,)
	for i in a:
		new = list()
		for j in ex:
			for v in range(0, a[i] + 1):
				new.append(j * i ** v)
		ex = new
	if len(ex) < k:
		print(-1)
	else:
		print(sorted(ex)[k - 1])
main()


(a, b) = map(int, input().split())
s = []
for i in range(1, int(a ** 0.5) + 1):
	if a % i == 0:
		s.append(i)
		if a // i != i:
			s.append(a // i)
s.sort()
if len(s) < b:
	print(-1)
else:
	print(s[b - 1])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	import math as my
	(n, m) = mj()
	L = []
	for i in range(1, int(my.sqrt(n)) + 1, 1):
		if n % i == 0:
			L.append(i)
			if i * i != n:
				L.append(n // i)
	L.sort()
	if len(L) < m:
		print(-1)
	else:
		print(L[m - 1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():

	def div(n):
		if n == 1:
			return [1]
		if n == 2:
			return [1, 2]
		if n == 3:
			return [1, 3]
		K = int(n ** 0.5)
		temp1 = []
		temp2 = []
		for i in range(1, K + 1):
			if n % i == 0:
				temp1 += [i]
				temp2 += [n // i]
		if temp1[-1] == temp2[-1]:
			temp2 = temp2[:-1]
		temp = temp1 + temp2[::-1]
		return temp
	(n, k) = list(map(int, input().strip().split(' ')))
	D = div(n)
	if len(D) < k:
		print(-1)
	else:
		print(D[k - 1])
main()


(n, k) = map(int, input().split())
t = []
p = 0
h = 0
for j in range(1, int(n ** 0.5) + 1):
	if n % j == 0:
		if j != n // j:
			t.append(n // j)
		p += 1
		if p == k:
			print(j)
			h += 1
			break
if h == 0:
	p -= k
	if abs(p) > len(t):
		print(-1)
	else:
		print(t[p])


import math
(n, k) = map(int, input().split())
sqrt = int(math.sqrt(n) + 1)
is_square = sqrt * sqrt == n
divisors = []
for i in range(1, sqrt):
	if n % i == 0:
		divisors.append(i)
		if i * i != n:
			divisors.append(n // i)
divisors.sort()
if k > len(divisors):
	print(-1)
else:
	print(divisors[k - 1])


(n, k) = map(int, input().split())
f = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		f += [i]
		if i * i != n:
			f += [n // i]
f = sorted(f)
print(-1 if len(f) < k else f[k - 1])


import math

def calculate(n, k):
	ctr = 0
	a = set()
	p = int(math.sqrt(n))
	for i in range(1, p + 1, 1):
		if n % i == 0:
			a.add(i)
			a.add(int(n / i))
	b = list(a)
	b.sort()
	if len(b) >= k:
		return b[k - 1]
	else:
		return -1
a = input().split()
c = calculate(int(a[0]), int(a[1]))
print(c)


(n, k) = map(int, input().split())
i = 2
ans = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		ans += [i]
		if i * i != n:
			ans += [n // i]
ans.sort()
if k > len(ans):
	print(-1)
else:
	print(ans[k - 1])


from math import sqrt, ceil, floor
arr = [int(i) for i in input().split()]
n = arr[0]
k = arr[1]
count = 0
arr = []
for i in range(1, floor(sqrt(n)) + 1):
	if n % i == 0:
		count += 1
		arr.append(i)
found = 0
arrs = arr[::-1]
if count == 0:
	print(-1)
elif len(arr) >= k:
	print(arr[k - 1])
	found = 1
else:
	for i in arrs:
		if n // i == i:
			continue
		else:
			arr.append(n // i)
			if len(arr) == k:
				print(arr[k - 1])
				found = 1
				break
if found == 0:
	print(-1)


(n, k) = map(int, input().split())
i = 0
l = []
c = 0
root = int(n ** 0.5)
for j in range(1, root + 1):
	if n % j == 0 and j * j != n:
		l.append(j)
		l.append(int(n / j))
		c += 2
	elif j * j == n:
		l.append(j)
		c += 1
l.sort()
if k > c:
	print(-1)
else:
	print(l[k - 1])


import math
(n, k) = input().split()
(n, k) = (int(n), int(k))
ans = []
ans = []
for i in range(1, int(math.sqrt(n) + 1)):
	if n % i == 0:
		ans.append(i)
		if n / i != i:
			ans.append(int(n / i))
mid = int(len(ans) / 2)
if len(ans) % 2 != 0:
	mid += 1
k -= 1
if len(ans) <= k:
	print(-1)
elif k < mid:
	print(ans[2 * k])
else:
	k %= mid
	print(ans[2 * (int(len(ans) / 2) - k - 1) + 1])


(n, k) = map(int, input().split())
i = 1
cont = 0
flag = 1
l = []
while i * i <= n:
	if n % i == 0:
		cont += 1
		l.append(i)
	if cont == k:
		print(i)
		flag = 0
		break
	i += 1
if flag:
	z = cont
	for i in range(z - 1, -1, -1):
		if n // l[i] != l[i]:
			l.append(n // l[i])
			cont += 1
		if cont == k:
			print(n // l[i])
			flag = 0
			break
	if flag:
		print(-1)


inf = float('inf')
read_ints = lambda : list(map(int, input().split()))

def solve(n, k):
	ls = []
	ncnt = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ncnt += 1
			ls.append(i)
			if ncnt == k:
				return i
	if ls[-1] ** 2 == n:
		if k >= 2 * ncnt:
			return -1
		return n // ls[2 * ncnt - 1 - k]
	else:
		if k > 2 * ncnt:
			return -1
		return n // ls[2 * ncnt - k]
(n, k) = read_ints()
print(solve(n, k))


import sys
import math

def factorization(n):
	res = []
	limit = math.ceil(math.sqrt(n))
	p = 2
	cnt = 0
	while n % p == 0:
		cnt += 1
		n //= p
	if cnt > 0:
		res.append((p, cnt))
	cnt = 0
	for p in range(3, limit + 1, 2):
		if n % p == 0:
			while n % p == 0:
				cnt += 1
				n //= p
			res.append((p, cnt))
		cnt = 0
	if n > 1:
		res.append((n, 1))
	return res

def divisor(n):
	res = set()
	factor = factorization(n)
	for (p, c) in factor:
		if res == set():
			for i in range(c + 1):
				res.add(p ** i)
		else:
			t = set()
			for i in range(1, c + 1):
				for m in res:
					t.add(m * p ** i)
			res = res | t
	res = list(sorted(res))
	return res
(n, k) = map(int, input().split())
n_div = divisor(n)
if n == 1:
	if k == 1:
		ans = 1
	else:
		ans = -1
elif k > len(n_div):
	ans = -1
else:
	ans = n_div[k - 1]
print(ans)


i = input().split()
a = int(i[0])
b = int(i[1])
x = 1
cont = []
for x in range(1, int(a ** 0.5) + 1):
	if a % x == 0:
		if x != a // x:
			cont += [x]
			cont += [a // x]
		else:
			cont += [x]
cont = sorted(cont)
print(-1 if len(cont) < b else cont[b - 1])


def div(x):
	d = []
	for i in range(1, 1 + int(x ** 0.5)):
		if x % i == 0:
			d.append(i)
			y = x // i
			if y != i:
				d.append(y)
	d.sort()
	return d
(n, k) = map(int, input().split())
dd = div(n)
if k <= len(dd):
	print(dd[k - 1])
else:
	print(-1)


import sys
import math
(n, k) = map(int, input().split())
divs = [0] * (int(math.sqrt(n)) + 1)
d = 0

def solve(n, k):
	global d
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divs[d] = i
			d += 1
			k -= 1
			if k == 0:
				return i
	if k > d:
		return -1
	if n // divs[d - 1] != divs[d - 1]:
		d -= 1
		k -= 1
	else:
		d -= 1
	if k > d:
		return -1
	else:
		return n // divs[d - k]
if n < k:
	print(-1)
else:
	print(solve(n, k))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def divisions(n):
	sq = int(math.sqrt(n) + 1)
	d = collections.defaultdict(int)
	while n % 2 == 0:
		n //= 2
		d[2] += 1
	i = 3
	while n > 1 and sq >= i:
		if n % i == 0:
			n //= i
			d[i] += 1
		else:
			i += 2
	if n > 1:
		d[n] += 1
	r = [1]
	for (k, v) in d.items():
		for c in r[:]:
			for i in range(1, v + 1):
				r.append(c * k ** i)
	return sorted(r)

def main():
	(n, k) = LI()
	d = sorted(divisions(n))
	if len(d) < k:
		return -1
	return d[k - 1]
print(main())


from math import sqrt
(n, k) = map(int, input().split())
if n == 1:
	if k == 1:
		print(1)
	else:
		print(-1)
else:
	i = 2
	t = sqrt(n)
	l = [1]
	l2 = [n]
	k -= 1
	while i < t:
		if n % i == 0:
			l.append(i)
			g = n // i
			l2.append(g)
		i += 1
	if i == t:
		l.append(i)
	a = len(l)
	b = len(l2)
	if k < a:
		print(l[k])
	elif k < a + b:
		k = k - a + 1
		print(l2[-k])
	else:
		print(-1)


(n, k) = map(int, input().split())

def factors(n):
	return set((x for tup in ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0) for x in tup))
b = factors(n)
c = list(b)
c.sort()
if len(b) < k:
	print(-1)
else:
	print(c[k - 1])


(n, k) = map(int, input().split())

def printDivisors(n):
	l = []
	i = 1
	while i * i < n:
		if n % i == 0:
			l.append(i)
			if len(l) >= k:
				break
		i += 1
	for i in range(int(n ** 0.5), 0, -1):
		if n % i == 0:
			l.append(n // i)
			if len(l) >= k:
				break
	return l
res = printDivisors(n)
if len(res) >= k:
	print(res[k - 1])
else:
	print(-1)


import math
(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
res = set()
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		res.add(i)
		res.add(int(n / i))
res = list(res)
if len(res) < k:
	print(-1)
else:
	res.sort()
	print(res[k - 1])


(n, k) = map(int, input().split())
f = []
for x in range(1, int(n ** 0.5) + 1):
	if n % x == 0:
		f.append(x)
		if x * x != n:
			f.append(n // x)
f.sort()
if len(f) < k:
	print(-1)
else:
	print(f[k - 1])


import sys
from math import sqrt
(n, k) = map(int, input().split())
div = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		if i * i != n:
			div.append(n // i)
		k -= 1
		if k == 0:
			print(i)
			exit()
for d in reversed(div):
	k -= 1
	if k == 0:
		print(d)
		exit()
print(-1)


import math

def divisors(n):
	sq = math.ceil(math.sqrt(n))
	d = set()
	for i in range(1, sq + 1):
		if n % i == 0:
			d.add(i)
			d.add(n // i)
	d.add(n)
	return sorted(d)
(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
d = divisors(n)
if k > len(d):
	print(-1)
else:
	print(d[k - 1])


from math import sqrt
(n, k) = [int(a) for a in input().split()]
d = []
q = 0
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		d.append(i)
		q += 1
		if n // i != i:
			d.append(n // i)
			q += 1
d = list(sorted(d))
if q < k:
	print(-1)
else:
	print(d[k - 1])


import math

def dvs(n, k):
	l = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			l.append(i)
			if i ** 2 != n:
				l.append(n // i)
	l.sort()
	if len(l) < k:
		print(-1)
	else:
		print(l[k - 1])
	return
(n, k) = map(int, input().split())
dvs(n, k)


(n, k) = map(int, input().split())
a = []
for i in range(1, n + 1):
	if i * i > n:
		break
	if n % i == 0:
		a.append(i)
		if i * i != n:
			a.append(n // i)
a.sort()
if k - 1 < len(a):
	print(a[k - 1])
else:
	print(-1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, k) = ria()
		i = 1
		div = []
		while i * i <= n:
			if n % i == 0:
				div.append(i)
				div.append(n // i)
			i += 1
		div = sorted(list(set(div)))
		if k > len(div):
			wi(-1)
		else:
			wi(div[k - 1])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def fact(n):
	s = set()
	x = 1
	while x * x <= n:
		if n % x == 0:
			s.add(n // x)
			s.add(x)
		x += 1
	s = list(sorted(s))
	return s
(n, k) = map(int, input().split())
l = fact(n)
if k > len(l):
	print(-1)
else:
	print(l[k - 1])


(n, k) = map(int, input().split())
l = []
i = 1
while i * i <= n:
	if n % i == 0:
		l.append(i)
		if i != n // i:
			l.append(n // i)
	i += 1
l = sorted(l)
if k <= len(l):
	print(l[k - 1])
else:
	print(-1)


(n, k) = map(int, input().split())
c = 2
if n == 1:
	c = 1
for i in range(2, int(n ** 0.5) + 1):
	if n % i == 0:
		c += 1
		if n // i != i:
			c += 1
if k > c:
	print(-1)
else:
	t = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			t += 1
			if t == k:
				print(i)
				break
			elif c - t + 1 == k:
				print(n // i)
				break


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy
import re
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby, count, filterfalse
from operator import itemgetter
for _ in range(1):
	(n, k) = LI()
	l = []
	import math

	def printDivisors(n):
		list = []
		for i in range(1, int(math.sqrt(n) + 1)):
			if n % i == 0:
				if n / i == i:
					list.append(i)
				else:
					list.append(i)
					list.append(int(n / i))
		return list
	z = printDivisors(n)
	z.sort()
	x = len(z)
	if k > x:
		print(-1)
	else:
		print(z[k - 1])


def get_divisors(n):
	limit = int(n ** 0.5) + 1
	for i in range(1, limit):
		if n % i == 0:
			yield i
			if i * i - n:
				yield (n // i)
(n, k) = [int(i) for i in input().split()]
answer = list(sorted(get_divisors(n)))
print(answer[k - 1] if len(answer) >= k else -1)


from math import pow, sqrt
(n, k) = map(int, input().split())
ls = []
limit = int(sqrt(n))
for i in range(1, limit + 1):
	if n % i == 0:
		ls.append(i)
length = len(ls)
if length == 1:
	if k == 1:
		print(1)
	elif k == 2 and n != 1:
		print(n)
	else:
		print(-1)
	exit()
sx = sqrt(n)
if int(sx) != sx:
	if k > 2 * length:
		print(-1)
	elif k <= length:
		print(ls[k - 1])
	else:
		print(int(n / ls[2 * length - k]))
elif k >= 2 * length:
	print(-1)
elif k <= length:
	print(ls[k - 1])
else:
	print(int(n / ls[2 * length - k - 1]))


from math import sqrt
(n, k) = map(int, input().split())
x = []
y = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		x.append(i)
		if n // i != i:
			y.append(n // i)
y.sort()
if k > len(x) + len(y):
	print(-1)
elif k <= len(x):
	print(x[k - 1])
else:
	print(y[k - len(x) - 1])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	(n, k) = read()
	divs = []
	divs2 = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			divs.append(i)
			if i ** 2 != n:
				divs2.append(n // i)
	divs2.reverse()
	divs += divs2
	if len(divs) < k:
		print(-1)
	else:
		print(divs[k - 1])
solve()


from math import sqrt
from collections import defaultdict

def divisors(n):
	a = [None] * 30030
	(a[0], t) = (1, 1)
	for i in range(2, 30030):
		if not a[i] is None:
			continue
		if t * i > 30030:
			break
		t *= i
		for j in range(i * 2, 30030, i):
			a[j] = 1
	a = [i for i in range(t) if a[i] is None]
	d = defaultdict(int)
	for i in a[1:]:
		while n % i == 0:
			n //= i
			d[i] += 1
	for j in range(1, int(sqrt(n) + 1) // t + 2):
		if t * j > n:
			break
		for ii in a:
			i = t * j + ii
			while n % i == 0:
				n //= i
				d[i] += 1
	if n > 1:
		d[n] += 1
	r = [1]
	for (k, v) in d.items():
		for c in r[:]:
			for i in range(1, v + 1):
				r.append(c * k ** i)
	return sorted(r)
(m, K) = [int(j) for j in input().split()]
lst = sorted(divisors(m))
if len(lst) < K:
	print(-1)
else:
	print(lst[K - 1])


import math
(n, k) = (int(i) for i in input().split())
if k == 1:
	print(1)
else:
	l = [1]
	c = 1
	k1 = 0
	k2 = 2
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			c += 1
			l += [i]
			k2 += 2
		if c == k:
			print(i)
			k1 = 1
			break
	if k1 == 0:
		if math.sqrt(n) == int(math.sqrt(n)):
			k2 -= 1
		if k2 < k:
			print(-1)
		elif k2 % 2 == 0:
			print(n // l[c - k + c])
		else:
			print(n // l[c - k + c - 1])


def MillerRabin(n):
	d = minus_one = n - 1
	for s in range(100000):
		if d & 1:
			for a in (2, 3, 5, 7, 11, 13, 17):
				a = pow(a, d, n)
				if a != 1:
					for _ in range(s):
						if a == minus_one:
							return True
						a = a * a % n
					else:
						return False
			return True
		d //= 2

def factor(x):
	(res, p, steps) = ({}, 2, (1, 2, 2, 4, 2))
	while True:
		if x < p * p:
			if x != 1:
				res[x] = 1
			return res
		for s in steps:
			while not x % p:
				x //= p
				res[p] = res.get(p, 0) + 1
			p += s
		steps = (4, 2, 4, 6, 2, 6, 4, 2)
from math import sqrt

def main():
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		return
	if MillerRabin(n):
		print(n if k == 2 else -1)
		return
	r = int(sqrt(n))
	if r * r == n and MillerRabin(r):
		print({1: 1, 2: r, 3: n}.get(k, -1))
		return
	divisors = [1]
	if k < 26881:
		for (p, v) in factor(n).items():
			divisors += [p * q for p in [p ** i for i in range(1, v + 1)] for q in divisors]
	print(-1 if len(divisors) < k else sorted(divisors)[k - 1])
main()


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
divs = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		divs.append(i)
if k <= len(divs):
	print(divs[k - 1])
elif n ** 0.5 % 1 == 0:
	if k < 2 * len(divs):
		print(n // divs[-(k - len(divs)) - 1])
	else:
		print(-1)
elif k <= 2 * len(divs):
	print(n // divs[-(k - len(divs))])
else:
	print(-1)


from math import ceil
(n, k) = map(int, input().split())
s = set()
for d in range(1, ceil(n ** 0.5) + 1):
	if n % d == 0:
		s.add(d)
		if d ** 2 != n:
			s.add(n // d)
if k > len(s):
	print(-1)
else:
	for (i, elem) in enumerate(sorted(s)):
		if i + 1 == k:
			print(elem)
			break


def main():
	a = list(map(int, input().split()))
	delit = [1]
	if a[0] != 1:
		delit.append(a[0])
	count = 1
	for i in range(2, int(a[0] ** 0.5) + 1):
		if a[0] % i == 0:
			delit.append(i)
			b = a[0] // i
			if i != b:
				delit.append(b)
	delit.sort()
	return -1 if len(delit) < a[1] else delit[a[1] - 1]
print(main())


import math
(n, k) = map(int, input().split())
divisors = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		divisors.append(i)
		if i ** 2 != n:
			divisors.append(n // i)
print(sorted(divisors)[k - 1] if k <= len(divisors) else -1)


import math
(n, k) = map(int, input().split())
divisors = []
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		divisors.append(i)
		divisors.append(n // i)
divisors = list(set(divisors))
divisors.sort()
if len(set(divisors)) < k:
	print(-1)
	exit()
print(divisors[k - 1])


import math

def solve(n, k):
	cnt = 0
	A = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			cnt += 1
			A.append(i)
		if cnt == k:
			return i
	bol = n // A[-1] == A[-1]
	if (cnt - bol) * 2 + bol >= k:
		return n // A[cnt - bol - k]
	return -1
(n, k) = map(int, input().split())
print(solve(n, k))


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
(n, k) = ll()
i = 2
l = set()
l.add(1)
l.add(n)
while i * i <= n:
	if n % i == 0:
		l.add(i)
		l.add(n // i)
	i += 1
if len(list(l)) < k:
	print(-1)
else:
	print(sorted(list(l))[k - 1])


import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans
karmanya = 0
for _ in range(int(input()) if karmanya else 1):
	(n, k) = map(int, input().split())
	div = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i != n // i:
				div += [i, n // i]
			else:
				div += [i]
	div.sort()
	if k > len(div):
		print(-1)
	else:
		print(div[k - 1])


def r():
	return list(map(int, input().split()))
(n, k) = r()
l = []
for i in range(1, int(n ** (1 / 2)) + 1):
	if n % i == 0:
		l.append(i)
		if i * i != n:
			l.append(n // i)
if k > len(l):
	print(-1)
	exit()
l.sort()
print(l[k - 1])


(n, k) = map(int, input().split())
l = []
ans = -1
for i in range(1, n + 1):
	if i * i > n:
		break
	if n % i == 0:
		k -= 1
		l.append(i)
	if k == 0:
		ans = i
		break
if ans != -1:
	print(ans)
elif l[-1] * l[-1] == n:
	if k > len(l) - 1:
		print(ans)
	else:
		print(n // l[len(l) - k - 1])
elif k > len(l):
	print(ans)
else:
	print(n // l[len(l) - k])


from math import ceil
(n, k) = map(int, input().split())
arr = []
fl = 0
if int(n ** 0.5) ** 2 == n:
	fl = 1
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		arr.append(i)
if n == k == 1:
	print(1)
elif k > len(arr) * 2 - fl:
	print(-1)
elif k <= len(arr):
	print(arr[k - 1])
else:
	print(n // arr[2 * len(arr) - k - fl])


import math
p = input().split()
m = int(p[0])
p = int(p[1])

def kthdivisor(n, k):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list = list + [i]
			else:
				list = list + [i]
				list = list + [int(n / i)]
	l = sorted(list)
	if len(l) < k:
		print(-1)
	else:
		print(l[k - 1])
kthdivisor(m, p)


(n, k) = map(int, input().split())
factors = []
d = 1
while d * d <= n:
	if n % d == 0:
		factors.append(d)
		if d * d != n:
			factors.append(n // d)
	d += 1
factors.sort()
print(-1 if k > len(factors) else factors[k - 1])


from time import time

def num_factors(n):
	results = set()
	for i in range(1, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			results.update([i, int(n / i)])
	return results
(n, k) = map(int, input().split())
ttt = time()
t = num_factors(n)
if len(t) < k:
	print(-1)
else:
	tt = list(t)
	tt.sort()
	print(tt[k - 1])


def getfctrlist(n):
	A = [1, n]
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
	A = set(A)
	A = list(A)
	return A
(n, k) = map(int, input().split())
F = getfctrlist(n)
F.sort()
if k > len(F):
	print('-1')
else:
	print(F[k - 1])


from collections import deque
(n, k) = map(int, input().split())
firsthalf = []
secondhalf = deque()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		firsthalf.append(i)
		if n // i != i:
			secondhalf.appendleft(n // i)
if k > len(firsthalf) + len(secondhalf):
	print(-1)
elif k > len(firsthalf):
	k -= len(firsthalf)
	print(secondhalf[k - 1])
else:
	print(firsthalf[k - 1])


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
(n, k) = mi()
d = sorted(divs(n))
if len(d) < k:
	print(-1)
else:
	print(d[k - 1])


from math import *
(n, k) = map(int, input().split())
l1 = []
l2 = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		if n // i == i:
			l1.append(i)
		else:
			l1.append(i)
			l2.append(n // i)
l1.extend(l2[::-1])
try:
	print(l1[k - 1])
except:
	print(-1)


import sys
(n, k) = [int(x) for x in sys.stdin.readline().split()]
factors = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		factors.add(i)
		if i // n != i:
			factors.add(n // i)
if k > len(factors):
	print('-1')
else:
	print(sorted(factors)[k - 1])


import sys
input = sys.stdin.readline

def read():
	return list(map(int, input().split()))
(n, k) = read()
i = 2
div = [1]
if n > 1:
	div.append(n)
while i * i <= n:
	if n % i == 0:
		div.append(i)
		if n // i != i:
			div.append(n // i)
	i += 1
div.sort()
if k > len(div):
	print(-1)
else:
	print(div[k - 1])


(n, k) = list(map(int, input().split()))
divs = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		divs.append(i)
		divs.append(n // i)
divs = list(set(divs))
divs.sort()
if k > len(divs):
	print(-1)
else:
	print(divs[k - 1])


def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def print_grid(grid):
	for line in grid:
		print(''.join(line))
from collections import Counter
import sys
import math
(n, k) = map(int, input().split())
ls = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		if i * i != n:
			ls += [i]
			ls += [n // i]
		else:
			ls += [i]
if len(ls) < k:
	print(-1)
else:
	print(sorted(ls)[k - 1])


(n, k) = map(int, input().split())
if n == 1:
	if k == 1:
		print(1)
	else:
		print(-1)
	exit()
from math import sqrt as S
res = []
res.append(1)
res.append(n)
for i in range(2, int(S(n)) + 1):
	if n % i == 0:
		if i == n // i:
			res.append(i)
		else:
			res.append(i)
			res.append(n // i)
res.sort()
if k > len(res):
	print(-1)
else:
	print(res[k - 1])


(n, k) = list(map(int, input().split()))
devs = []
iter = 1
while iter * iter <= n:
	if n % iter == 0:
		if iter * iter == n:
			devs.append(iter)
		else:
			devs.append(iter)
			devs.append(n // iter)
	iter += 1
devs.sort()
if k > len(devs):
	print(-1)
else:
	print(devs[k - 1])


import sys
from math import sqrt, floor
from collections import Counter

def factorize(n):
	limit = floor(sqrt(n))
	factor = Counter()
	p = 2
	while n % p == 0:
		factor[p] += 1
		n //= p
	for p in range(3, limit + 1, 2):
		while n % p == 0:
			factor[p] += 1
			n //= p
	if n > 1:
		factor[n] += 1
	return factor

def make_divisors(n):
	result = [1]
	for (p, e) in factorize(n).items():
		result = [x * p ** i for i in range(e + 1) for x in result]
	return sorted(result)
(n, k) = map(int, input().split())
divisors = make_divisors(n)
if k > len(divisors):
	ans = -1
else:
	ans = divisors[k - 1]
print(ans)


def getDivs(n):
	res = [1]
	if n == 1:
		return res
	p = 2
	while p * p <= n:
		if n % p == 0:
			c = p
			res2 = res[:]
			while n % p == 0:
				res.extend([c * x for x in res2])
				c *= p
				n //= p
		p += 1
	if n > 1:
		res.extend([n * x for x in res])
	res.sort()
	return res
(n, k) = map(int, input().split())
ds = getDivs(n)
if k > len(ds):
	print(-1)
else:
	print(ds[k - 1])


from math import sqrt
(x, y) = map(int, input().split())
lol = []
for i in range(1, int(sqrt(x)) + 1):
	if x % i == 0:
		if x // i == i:
			lol.append(i)
		else:
			lol.append(x // i)
			lol.append(i)
lol.sort()
if len(lol) >= y:
	print(lol[y - 1])
else:
	print(-1)


import math, bisect
(a, b) = input().split()
(a1, a2) = (int(a), int(b))
arr = []
arr1 = []
i = 1
while i <= math.sqrt(a1) + 1:
	if a1 % i == 0:
		if a1 / i == i:
			bisect.insort(arr, i)
		else:
			bisect.insort(arr, i)
			bisect.insort(arr1, int(a1 / i))
	i = i + 1
arr.extend(arr1)
arr = list(set(arr))
arr.sort()
if len(arr) < a2:
	print(-1, end='')
else:
	print(arr[a2 - 1], end='')


import math
ls = []
(ctr, f) = (0, 1)
(n, k) = map(int, input().split())
for i in range(1, math.ceil(math.sqrt(n)) + 1):
	if n % i == 0:
		ls.append(i)
		ls.append(n // i)
		ctr += 1
	if ctr == k:
		f = 0
		print(ls[-2])
		break
ls = list(set(ls))
if f:
	if len(ls) >= k:
		ls.sort()
		print(ls[k - 1])
	else:
		print(-1)


def solve(n, k):
	cnt = 0
	A = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt += 1
			A.append(i)
		if cnt == k:
			return i
	bol = n // A[-1] == A[-1]
	if (cnt - bol) * 2 + bol >= k:
		return n // A[cnt - bol - k]
	return -1
(n, k) = map(int, input().split())
print(solve(n, k))


import math
(n, k) = [int(i) for i in input().split()]
answer_list_front = []
answer_list_back = []
check_upper_lim = int(math.sqrt(n))
for i in range(1, check_upper_lim + 1):
	if n % i == 0:
		answer_list_front.append(i)
		answer_list_back.append(n // i)
if i == n / i:
	answer_list_back = answer_list_back[:-1]
len_front = len(answer_list_front)
len_back = len(answer_list_back)
if len_front + len_back < k:
	print(-1)
elif len_front >= k:
	print(answer_list_front[k - 1])
else:
	print(answer_list_back[len_back + len_front - k])


import math

def read(type=int):
	return type(input())

def read_arr(type=int):
	return [type(token) for token in input().split()]

def solution(n, k):
	small = []
	large = []
	s = int(math.sqrt(n))
	for i in range(1, s + 1):
		if n % i == 0:
			small.append(i)
			if n // i != i:
				large.append(n // i)
	f = small + list(reversed(large))
	return f[k - 1] if k <= len(f) else -1

def run():
	(n, k) = read_arr()
	ans = solution(n, k)
	if ans is None:
		ans = -1
	print(ans)
run()


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
dividersl = []
dividersu = []
dividers = []
for i in range(1, int(n ** 0.5) + 1):
	if not n % i and i != n // i:
		dividersl.append(i)
		dividersu.append(n // i)
	elif not n % i:
		dividersl.append(i)
dividers = dividersl + dividersu[::-1]
if k > len(dividers):
	stdout.write('-1')
else:
	stdout.write(str(dividers[k - 1]))


import math
d = []

def divisors(n, k):
	p = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			d.append(i)
			if n // i == i:
				p = 1
			k -= 1
		if k == 0:
			return (True, i, p)
	return (False, -1, p)
(n, k) = map(int, input().split())
(found, ans, parity) = divisors(n, k)
if found:
	print(ans)
else:
	l = len(d)
	if parity == 0 and k <= 2 * l:
		print(n // d[2 * l - k])
	elif parity == 1 and k <= 2 * l - 1:
		print(n // d[2 * l - 1 - k])
	else:
		print('-1')


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	nk = list(map(int, input().split()))
	(n, k) = (nk[0], nk[1])
	x = int(math.sqrt(n))
	(s, t) = ([], [])
	for i in range(1, x + 1):
		if n % i == 0:
			s.append(i)
			if n // i != i:
				t.append(n // i)
	st = s + t[::-1]
	if len(st) < k:
		print(-1)
	else:
		print(st[k - 1])
main()


from math import *
from sys import stdin
input = stdin.readline
(n, k) = map(int, input().split())
li = []
for i in range(1, floor(sqrt(n)) + 1):
	if n % i == 0:
		li.append(i)
		if i != n // i:
			li.append(n // i)
if k > len(li):
	print(-1)
else:
	print(sorted(li)[k - 1])