package string;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Integer.parseInt;
import static java.lang.System.in;
public class ContinuousLetterLength {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
String str = bf.readLine();
int k = parseInt(bf.readLine());
bf.close();
Map<Character, Integer> map = getCharAndSizeMap(str);
map.values().stream().sorted(Comparator.reverseOrder()).skip(k - 1).limit(1).forEach(System.out::println);
}
private static Map<Character, Integer> getCharAndSizeMap(String str) {
Map<Character, Integer> map = new HashMap<>();
Deque<Character> dynamicChars;
for (int i = 0; i < str.length(); ) {
dynamicChars = new LinkedList<>();
while (i < str.length() && (dynamicChars.isEmpty() || dynamicChars.contains(str.charAt(i)))) {
dynamicChars.addLast(str.charAt(i));
i = i + 1;
}
Integer tempMax = map.getOrDefault(dynamicChars.getFirst(), 0);
map.put(dynamicChars.getFirst(), Math.max(tempMax, dynamicChars.size()));
}
return map;
}
}