#include <bits/stdc++.h>
#define NMAX 50500
using namespace std;
const int base=256;
const int mod=1e9+7;
string s;
int n,k;
int Hash[NMAX],pw[NMAX+1];
void prepare()
{
    cin>>n>>k>>s;
    s='#'+s;
    pw[0]=1;
    for(int i=1;i<=NMAX;i++)  pw[i]=1ll*pw[i-1]*base%mod;

    for(int i=1;i<=n;i++)  Hash[i]=(Hash[i-1]+1ll*((int)s[i])*pw[i-1])%mod;

  //  for(int i=1;i<=n;i++)  cout<<Hash[i]<<" ";
}
int gethash(int l,int r)
{
    int temp=Hash[r]-Hash[l-1];
    if(temp<0)  temp+=mod;
    return 1ll*temp*pw[NMAX-l+1]%mod;
}
bool check_hash(int mask)
{
    map<int,int> mp;
    for(int i=1;i<=n-mask+1;i++)
    {
        mp[gethash(i,i+mask-1)]++;
    }
    for(pair<int,int> u:mp)
    {
        if(u.second>=k) return true;
    }
    return false;
}
void process()
{
    int l=1,r=n,ans=1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check_hash(mid))
        {
            ans=mid;
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }

    }
    cout<<ans;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    prepare();
    process();
    return 0;
}
