s,k=open(0);k=int(k);q=[];N=len(s)

for i in range(N):

 for j in range(min(k,N-1-i)):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]

print((q[-1]))
s=eval(input());k=int(eval(input()));q=[]

for i in range(len(s)):

 for j in range(k):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]

print((q[-1]))
s, k = open(0)
k = int(k)
q = []
N = len(s)
for i in range(N):
    for j in range(min(k, N - 1 - i)):
        x = s[i : i + j + 1]
        q = q if x in q else sorted(q + [x])[:k]
print((q[-1]))

s = eval(input())
k = int(eval(input()))
q = []
for i in range(len(s)):
    for j in range(k):
        x = s[i : i + j + 1]
        q = q if x in q else sorted(q + [x])[:k]
print((q[-1]))

-s, k = open(0) -k = int(k) +s = eval(input()) +k = int(eval(input())) -N = len(s) -for i in range(N): -    for j in range(min(k, N - 1 - i)): +for i in range(len(s)): +    for j in range(k):