#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
bool c(const string &s, int L, int k)
{
int n = s.size();
vector<int> ch(L, 0);
for (int i = 0; i < n; ++i)
{
if (s[i] != s[i % L])
{
++ch[i % L];
}
}
int tot = accumulate(ch.begin(), ch.end(), 0);
return tot <= k;
}
int f(const string &s, int k)
{
int n = s.size();
for (int L = 1; L <= n; ++L)
{
if (n % L == 0 && c(s, L, k))
{
return L;
}
}
return n;
}
int main()
{
int k;
string s;
cin >> k;
cin >> s;
cout << f(s, k) << endl;
return 0;
}