#include "bits/stdc++.h"
#define task "Tank"
#define endl '\n'
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using vi = vector <int>;
bool maxi(auto &u, auto v)
{
if (u >= v) return 0;
return u = v, true;
}
bool mini(auto &u, auto v)
{
if (u <= v) return 0;
return u = v, true;
}
const int N = 1e6 + 6;
int n, k;
string s;
void Solve()
{
int dp[n][2] = {0};
int x1 = 0, y1 = -1;
int x2 = 0, y2 = -1;
int mx = 0, ans = 0;
for (int i = 0; i < n; i++)
{
int k = 0;
if (i > y1) k = 1;
else k = min(dp[x1 + y1 - i][0], y1 - i + 1);
while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) k++;
dp[i][0] = k--;
if (i + k > y1) x1 = i - k, y1 = i + k;
if (2 * dp[i][0] - 1 > mx) ans = i - k, mx = 2 * dp[i][0] - 1;
k = 0;
if (i <= y2) k = min(dp[x2 + y2 - i + 1][1], y2 - i + 1);
while(0 <= i - k - 1 && i + k < n && s[i - k - 1] == s[i + k]) k++;
dp[i][1] = k--;
if (i + k > y2) x2 = i - k - 1, y2 = i + k;
if (2 * dp[i][1] > mx) ans = i - k - 1, mx = 2 * dp[i][1];
}
cout << mx;
}
signed main()
{
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> k >> s;
string t = s;
n *= k;
for (int i = 1; i < k; ++i)
s += t;
///cout << s;
Solve();
return 0;
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCiNkZWZpbmUgdGFzayAiVGFuayIKI2RlZmluZSBlbmRsICdcbicKI2RlZmluZSBGIGZpcnN0CiNkZWZpbmUgUyBzZWNvbmQKI2RlZmluZSBhbGwodikgKHYpLmJlZ2luKCksKHYpLmVuZCgpCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBsbCA9IGxvbmcgbG9uZzsKdXNpb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PCBuICYmIHNbaSAtIGsgLSAxXSA9PSBzW2kgKyBrXSkgaysrOwogICAgICAgIGRwW2ldWzFdID0gay0tOwogICAgICAgIGlmIChpICsgayA+IHkyKSB4MiA9IGkgLSBrIC0gMSwgeTIgPSBpICsgazsKICAgICAgICBpZiAoMiAqIGRwW2ldWzFdID4gbXgpIGFucyA9IGkgLSBrIC0gMSwgbXggPSAyICogZHBbaV1bMV07CiAgICB9CiAgICBjb3V0IDw8IG14Owp9CgpzaWduZWQgbWFpbigpCnsKICAgIGlmIChmb3Blbih0YXNrIi5pbnAiLCAiciIpKQogICAgewogICAgICAgIGZyZW9wZW4odGFzayIuaW5wIiwgInIiLCBzdGRpbik7CiAgICAgICAgZnJlb3Blbih0YXNrIi5vdXQiLCAidyIsIHN0ZG91dCk7CiAgICB9CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CgogICAgY2luID4+IG4gPj4gayA+PiBzOwogICAgc3RyaW5nIHQgPSBzOwogICAgbiAqPSBrOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBrOyArK2kpCiAgICAgICAgcyArPSB0OwogICAgLy8vY291dCA8PCBzOwoKICAgIFNvbHZlKCk7CgogICAgcmV0dXJuIDA7Cn0=