#include <bits/stdc++.h>
using namespace std;

int main()
{
    string g;
    int n, k;
    cin >> n >> k >> g;

    int maxi = -1;

    for (int i = 0; i <= n - 1; i++)
    {
        unordered_map<char, int> b; // In this map only distinct characters and distinct frequency is stored 

        for (int j = i; j <= n - 1; j++)
        {
            // Count the current character
            char number = g[j]; // g[j] means original input string store in number
            b[number] = b[number] + 1; // and increment it count the currrent character

            int l = j - i + 1;

            // Check exactly k distinct characters
            if (b.size() == k) // b.size will give us number key- value pairs stored in map 
            {
                maxi = max(maxi, l);
            }
        }
    }

    cout << maxi << endl;

    return 0;
}