private static void solve() throws IOException {

        String s = next();
        int k = nextInt();

        //Move window from 0 and up to K unique chars.
        Map<Character, Integer> hist = new HashMap<>();
        int i = 0;
        while (hist.size() < k) {
            if (i >= s.length()) {
                pw.println("Insufficient unique chars");
                return;
            }
            char c = s.charAt(i);
            int count = 0;
            if (hist.containsKey(c)) {
                count = hist.get(c);
            }
            hist.put(c, count + 1);
            i++;
        }

        //That is our max window for now.
        int max_start = 0;
        int max_end = i - 1;
        int curr_start = 0;

        //Start from i, if a new unique char found, remove from begging untill unique chars = k;
        for (; i < s.length(); i++) {

            //Add next char to hist
            char c = s.charAt(i);
            int count = 0;
            if (hist.containsKey(c)) {
                count = hist.get(c);
                hist.put(c, count + 1);
            }
            hist.put(c, count + 1);

            //if new chars exceeds K, start removing from front
            while (hist.size() > k) {
                char c1 = s.charAt(curr_start);
                int _count = hist.remove(c1);
                if (_count != 1) {
                    hist.put(c1, _count - 1);
                }
                curr_start++;
            }

            //Update max_end if required
            if (max_end - max_start < i - curr_start) {
                max_start = curr_start;
                max_end = i;
            }
        }

        for (int j = max_start; j <= max_end; j++) {
            pw.print(s.charAt(j));
        }

        pw.println();

    }