Question
Find Longest Substring

You are given a string S consisting only of lowercase English letters, and an integer K.

Find the length of the longest contiguous substring of S that contains at most K distinct characters.

Input

The first line contains the string KaTeX can only parse string typed expression (this line may be empty).

The second line contains a single integer KaTeX can only parse string typed expression.

Output

Print a single integer — the length of the longest substring containing at most KaTeX can only parse string typed expression distinct characters.

Example
Example 1:
Input
eceba

2
Output
3
Explanation
The substring "ece" (indices 0-2) has exactly 2 distinct characters ('e' and 'c') and length 3, which is the longest such substring.

Example 2:
Input
aaabbbccc

1
Output
3
Explanation
With at most 1 distinct character allowed, the longest valid substring is any single run of the same repeated character, such as "aaa", "bbb", or "ccc", each of length 3.

Example 3:
Input
abcabc

0
Output
0
Explanation
With KaTeX can only parse string typed expression, no substring is allowed to contain any character at all, so the only valid substring is the empty one, with length 0.

Online