#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    string s;
    cin>>s;
    int cnt;
    if(s=="SUN") {
        cnt=7;
    }
    elif(s=="MON") {
        cnt=6;
    }
    elif(s=="TUE") {
        cnt=5;
    }
    elif(s=="WED") {
        cnt=4;
    }
    elif(s=="THU") {
        cnt=3;
    }
    elif(s=="FRI") {
        cnt=2;
    }
    elif(s=="SAT") {
        cnt=1;
    }

    cout<<cnt<<endl;

    
    // ()?cout<<"1"<<endl:cout<<"0"<<endl;
    
    return 0;
}
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
const int oo=2139063143;
const int N=310;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
void chkmax (int &A,int B) { A=A>=B?A:B; }
char s[N];
int f[N][N][N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	scanf ("%s",s+1);
	int n=strlen (s+1),k; sc(k);
	for (int i=1; i<=n; i++)
		f[i][i][0]=1;
	for (int len=2; len<=n; len++)
	{
		for (int l=1,r=len; r<=n; l++,r++)
		{
			for (int i=0; i<=k; i++)
			{
				f[l][r][i]=max (f[l+1][r][i],f[l][r-1][i]);
				if (s[l]==s[r]) chkmax (f[l][r][i],f[l+1][r-1][i]+2);
				if (i) chkmax (f[l][r][i],f[l+1][r-1][i-1]+2);
			}
		}
	}
	int ans=0;
	for (int i=0; i<=k; i++)
		chkmax (ans,f[1][n][i]);
	pr(ans);

	return 0;
}
