using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC124_D
{
    class Program
    {
        class Node
        {
            public int leftCount;
            public int rightCount;
            public int myCount;
            public int sum;
            public Node prevOtherNode;
            public Node nextOtherNode;

            public bool current01Flag;
        }

        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int n = int.Parse(strs[0]);
            int k = int.Parse(strs[1]);

            string s = Console.ReadLine();

            var node0 = new Node[50000];
            var node1 = new Node[50000];

            Node firstNode = null;
            Node lastNode = null;

            int katamari0Count = 0;
            int katamari1Count = 0;
            bool current01Flag = true;
            bool prev01Flag = true;

            Node currentNode0 = null;
            Node currentNode1 = null;

            int maxCount = 0;

            if (s[0] == '1')
            {
                prev01Flag = true;
                katamari1Count = 1;

                currentNode1 = new Node();
                currentNode1.current01Flag = true;
                firstNode = currentNode1;

                current01Flag = true;
            }
            else
            {
                prev01Flag = false;
                katamari0Count = 1;

                currentNode0 = new Node();
                currentNode0.current01Flag = false;
                firstNode = currentNode0;

                current01Flag = false;
            }

            // 0または1のかたまりを探す
            for (int i = 1; i < n; ++i)
            {
                if (s[i] == '1')
                {
                    current01Flag = true;

                    if (prev01Flag != current01Flag)
                    {
                        currentNode0.myCount = katamari0Count;

                        katamari1Count = 1;

                        var prevNode = currentNode1;

                        currentNode1 = new Node();
                        currentNode1.current01Flag = true;
                        currentNode0.nextOtherNode = currentNode1;
                        currentNode1.prevOtherNode = currentNode0;
                    }
                    else
                    {
                        ++katamari1Count;
                    }
                }
                else
                {
                    current01Flag = false;

                    if (prev01Flag != current01Flag)
                    {
                        currentNode1.myCount = katamari1Count;
                        if (maxCount < katamari1Count)
                        {
                            maxCount = katamari1Count;
                        }
                        katamari0Count = 1;

                        var prevNode = currentNode0;

                        currentNode0 = new Node();
                        currentNode0.current01Flag = false;
                        currentNode1.nextOtherNode = currentNode0;
                        currentNode0.prevOtherNode = currentNode1;
                    }
                    else
                    {
                        ++katamari0Count;
                    }
                }

                prev01Flag = current01Flag;
            }

            if (current01Flag)
            {
                currentNode1.myCount = katamari1Count;
                if (maxCount < katamari1Count)
                {
                    maxCount = katamari1Count;
                }

                lastNode = currentNode1;
            }
            else
            {
                currentNode0.myCount = katamari0Count;

                lastNode = currentNode0;
            }

            {
                Node currentNode = firstNode;
                Node[] nodeBuffer = new Node[k];
                int nodeBufferIndex = 0;
                int nodeBufferSum = 0;

                while (currentNode != null)
                {
                    currentNode.leftCount = nodeBufferSum;

                    if (nodeBuffer[nodeBufferIndex] != null)
                    {
                        nodeBufferSum -= nodeBuffer[nodeBufferIndex].myCount;
                    }
                    nodeBuffer[nodeBufferIndex] = currentNode;
                    nodeBufferSum += currentNode.myCount;
                    nodeBufferIndex = (nodeBufferIndex + 1) % k;

                    currentNode = currentNode.nextOtherNode;
                }
            }

            // kの数が奇数の時は0のかたまりのところに、偶数の時は1のかたまりのところに合計数を書き込む
            bool write01Flag = (k % 2 == 0);

            {
                Node currentNode = lastNode;
                Node[] nodeBuffer = new Node[k];
                int nodeBufferIndex = 0;
                int nodeBufferSum = 0;

                while (currentNode != null)
                {
                    currentNode.rightCount = nodeBufferSum;
                    if (write01Flag == currentNode.current01Flag)
                    {
                        currentNode.sum = currentNode.leftCount + currentNode.myCount + currentNode.rightCount;
                        if (maxCount < currentNode.sum)
                        {
                            maxCount = currentNode.sum;
                        }
                    }

                    if (nodeBuffer[nodeBufferIndex] != null)
                    {
                        nodeBufferSum -= nodeBuffer[nodeBufferIndex].myCount;
                    }
                    nodeBuffer[nodeBufferIndex] = currentNode;
                    nodeBufferSum += currentNode.myCount;
                    nodeBufferIndex = (nodeBufferIndex + 1) % k;

                    currentNode = currentNode.prevOtherNode;
                }
            }

            if (maxCount == 0) { maxCount = n; }

            Console.WriteLine("{0}", maxCount);
        }
    }
}


Measured memory_bytes: 22368