This page is still under construction.

Parts of this page are still being built. What you see may change.

Words

Time limit1sMemory limit128 MB

Summary
Given a word of length n, find the smallest number of blocks in a word that differs from it in at most k positions.
Level

Medium7 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

A word is a sequence of capital letters of the English alphabet. The length of a word is the number of letters it contains. For example, the word α\alpha = ABAACBBBA has length 99.

A block of a word is a maximal run of identical letters. A word is tt-hard if it consists of exactly tt blocks. The word α\alpha above is 66-hard, because it splits into the blocks A | B | AA | C | BBB | A.

Two words of the same length can be compared by how much they differ. Two words of length nn are kk-different if they differ in exactly kk positions ii (with 1≤i≤n1 \le i \le n): the ii-th letter of the first word differs from the ii-th letter of the second. For example, α\alpha and β\beta = AAAABBBBB are 33-different.

Given a word α\alpha, we want a word β\beta that is not too different from α\alpha yet as simple as possible, and we ask how simple β\beta can be.

Write a program that reads nn, kk, and a word α\alpha of length nn, and finds the smallest tt such that there exists a tt-hard word β\beta differing from α\alpha in at most kk positions. Output this value of tt.

Input

The first line contains two integers nn and kk separated by a single space (1≤n≤10001 \le n \le 1000, 0≤k≤n0 \le k \le n): the length of the word α\alpha and the allowed number of differing positions. The second line contains exactly nn capital letters forming the word α\alpha.

Output

Output a single integer: the minimum value of tt.

Examples3

  1. Example 1

    Input
    9 3
    ABAACBBBA
    
    Expected output
    2
    
  2. Example 2

    Input
    9 0
    ABAACBBBA
    
    Expected output
    6
    
  3. Example 3

    Input
    5 2
    AAAAA
    
    Expected output
    1