public class SubstringComparisons {
    // https://www.hackerrank.com/challenges/java-string-compare/problem

    public SubstringComparisons() {
        // Brute force is O(n^2) by looping through array and using String.compareTo()
        // We can achieve O(nlogn) by sorting first

        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int k = scan.nextInt();
        scan.close();

        // Populate array
        String[] array = new String[s.length() - k + 1];
        for (int i = 0; i < s.length() - k + 1; i++) {
            String substring = s.substring(i, i + k);
            array[i] = substring;
        }

        // Sort array and write out answer
        Arrays.sort(array);
        System.out.println(array[0] + "\n" + array[array.length - 1]);
    }
}