#include <bits/stdc++.h>
using namespace std;
#define MAX_N 16384
#define MAX_LOG 14 // 2^14 = MAX_N
#define BASE 123
int n, k;
char s[MAX_N + 1];
unordered_map<unsigned int, int> freq;
// Maximum number of occurrences of a substring of length len
int maxOccurrences(int len) {
int i, maxFreq;
unsigned int curHash, power;
curHash = 0;
for (i = 0; i < len; ++i)
curHash = curHash * BASE + s[i];
power = 1;
for (i = 1; i < len; ++i)
power *= BASE;
freq.clear();
freq[curHash] = 1;
maxFreq = 1;
for (i = len; i < n; ++i) {
curHash -= s[i - len] * power; // Remove the first character
curHash = curHash * BASE + s[i]; // Add the new character
++freq[curHash];
maxFreq = max(maxFreq, freq[curHash]);
}
return maxFreq;
}
int longestLength() {
int len, step;
len = 0;
for (step = 1 << MAX_LOG; step > 0; step >>= 1)
if (len + step <= n && maxOccurrences(len + step) >= k)
len += step;
return len;
}
int main() {
FILE *fin, *fout;
fin = fopen("substr.in", "r");
fout = fopen("substr.out", "w");
fscanf(fin, "%d%d %s", &n, &k, s);
freq.reserve(n);
fprintf(fout, "%d\n", longestLength());
fclose(fin);
fclose(fout);
return 0;
}