#include <cstdio>
#include <iostream>
using namespace std;
const int N = 11;
string str;
int n;
char ch[N];
long long res;
void solve (int dep) {
if (dep > n) {
long long ans = 0;
string t = "";
for (int i = dep - 1; i > 0; i--) {
t = ch[i] + t;
int j = 0;
while (str[j] == t[j] && j < t.size()) {
j++;
}
ans += j;
}
res = max (res, ans);
return;
}
for (char c = 'a'; c <= 'z'; c++) {
ch[dep] = c;
solve (dep + 1);
}
}
int main () {
freopen ("string.in", "r", stdin);
freopen ("string.out", "w", stdout);
cin >> str >> n;
solve (1);
cout << res << endl;
return 0;
}