This page is still under construction.

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

Type Two de Bruijn Sequences

Time limit2sMemory limit512 MB

Summary
Given a binary string, append the fewest digits so that every length-n binary word appears as a subsequence.
Level

Medium7 of 10

Topics
Greedy, String, Dynamic programming
Solved
No attempts yet

Problem

A word ss made up of 2n+n−12^n + n - 1 characters 0 and 1 is called a de Bruijn sequence of order nn if every nn-character binary word appears as one of its subwords, that is a fragment of consecutive characters of ss. For example, 0001011100 is a de Bruijn sequence of order 3.

A type two de Bruijn sequence of order nn is a word ss of arbitrary length such that every nn-character binary word appears as a subsequence of ss, that is a fragment of characters that are not necessarily consecutive. For example, 00101101 is a type two de Bruijn sequence of order 3. As far as we know, Nicolaas Govert de Bruijn did not invent such sequences, but their definition is clearly similar to the original one.

Consider a word ss made up only of zeroes and ones. How many digits (0 or 1) must be appended to the end of ss so that it becomes a type two de Bruijn sequence of order nn?

Input

The first line contains two integers mm and nn (1≤m,n≤1061 \le m, n \le 10^6) separated by a single space. The second line contains the mm-character word ss, made up only of the digits 0 and 1, with no spaces.

Output

Print a single non-negative integer: the minimal number of digits that must be appended to the end of ss so that it becomes a type two de Bruijn sequence of order nn.

Hint

For s=s = 00101 with n=3n = 3, appending the two characters 01 gives 0010101, which is a type two de Bruijn sequence of order 3. Hence the answer is 2.

Examples1

  1. Example 1

    Input
    5 3
    00101
    
    Expected output
    2