/*
dp[i][j][k] 前i个字符和后j个字符最多修改k个字符的最大长度

dp[i][j][k] = max(
                  dp[i-1][j][k],
                  dp[i][j-1][k],
                  if s[i] == s[n-1-j] : dp[i-1][j-1][k]+1
                  else : dp[i-1][j-1][k-1] + 1)

abcabcabc
cbacbacba


*/

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int n,m;
char s[305];
int dp[305][305][305];

int main(){
    int i,j,k;
    while(~scanf("%s%d",s,&m)){
        n = strlen(s);
        dp[0][0][0] = s[0]==s[n-1]? 1 : 0;
        for(i = 1;i <= m;i++){
            dp[0][0][i] = 1;
        }
        for(i = 0;i < n;i++){
            for(j = 0;j < n;j++){
                if(i+j==0) continue;
                for(k = 0;k <= m;k++){
                    dp[i][j][k] = max(i>0?dp[i-1][j][k]:-1,j>0?dp[i][j-1][k]:-1);
                    if(i > 0 && j > 0)
                    if(s[i] == s[n-1-j]){
                        dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k]+1);
                    }else{
                        dp[i][j][k]= max(dp[i][j][k],dp[i-1][j-1][k-1]+1);
                    }
                }
            }
        }
        printf("%d\n",dp[n-1][n-1][m]+m);

    }

    return 0;
}
