import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();

        String s = sc.nextLine();

        TreeMap<Character, Integer> map = new TreeMap<>();

        int left = 0;
        int maxLength = 0;

        for (int right = 0; right < n; right++) {

            char ch = s.charAt(right);

            // Add current character
            map.put(ch, map.getOrDefault(ch, 0) + 1);

            // Shrink window while invalid
            while (map.lastKey() - map.firstKey() > k) {

                char leftChar = s.charAt(left);

                map.put(leftChar, map.get(leftChar) - 1);

                if (map.get(leftChar) == 0) {
                    map.remove(leftChar);
                }

                left++;
            }

            maxLength = Math.max(maxLength, right - left + 1);
        }

        System.out.println(maxLength);
    }
}