#include<bits/stdc++.h>
using namespace std;
char s[305],c[305];
int k;
int f[305][305][305];
int mymax(int a,int b,int c)
{
	return max(max(a,b),c);
}
int main() {
	scanf("%s",s);
	scanf("%d",&k);
	int n = strlen(s);
	for (int i=0;i<n/2;i++)
		c[i]=s[n-i-1];
	f[0][0][0]=0;
	for(int i=1; i<=n/2; i++) {
		for(int j=1; j<=n/2; j++) {
			if(s[i-1]==c[j-1])
				f[i][j][0] = f[i-1][j-1][0] + 1;
			else
				f[i][j][0] = max(f[i-1][j][0], f[i][j-1][0]);
		}
	}
	for(int m=1; m<=k; m++) {
		for(int i=1; i<=n/2; i++) {
			for(int j=1; j<=n/2; j++) {
				if(s[i-1]==c[j-1])
					f[i][j][m] = max(f[i-1][j-1][m],f[i-1][j-1][m-1])+1;
				else
					f[i][j][m] = mymax(f[i-1][j-1][m-1]+1, f[i][j-1][m], f[i-1][j][m]);
			}
		}
	}
	int ans = f[n/2][n/2][k]*2;
	if(n%2)	ans+=1;
	cout<<ans;
	return 0;
}