#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 303;
char s[N];
int n,k,f[N][N][N];
inline void umax(int &a, int b) {a=a>b?a:b;}
int main() {
	scanf("%s",s+1); read(k); n=strlen(s+1);
	rep(i,1,n) f[i][i][0]=1; int ans=0;
	rep(l,-1,n-1) rep(i,1,n) {
		int j=i+l; if (j>n) break;
		rep(K,0,k) {
			int v=f[i][j][K]; umax(ans,v);
			umax(f[i][j+1][K],v); umax(f[i-1][j][K],v);
			umax(f[i-1][j+1][K+(s[i-1]!=s[j+1])],v+2);
		}
	}
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define pii pair <int, int>
#define x first
#define y second

using namespace std;

string s;
int dp[301][301][301];

inline int solve(int l, int r, int k) {
    if (k < 0)
        return INT_MIN;
    if (r - l < 1)
        return r - l + 1;
    if (dp[l][r][k] != -1)
        return dp[l][r][k];
    return dp[l][r][k] = max(solve(l + 1, r - 1, k - (s[l] != s[r])) + 2, max(solve(l + 1, r, k), solve(l, r - 1, k)));
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int k;
    cin >> s >> k;
    memset(dp, -1, sizeof(dp));
    return cout << solve(0, s.length() - 1, k), 0;
}
