jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky
32
 kbxuunznjtxutlauuuipifggjjkequbpvbagmxojhgxtakxioxsmrmoatlyzwsygibhafspqnfbycyztxmtpirqcyhalluhhubne
100
 zwvrx
3
 wccknxhbqzjwaseubvizxuisnzneatgjhaatrfydssgzufyztesrxnjlbhckybqlbncvqgjcoupirpqnnmacejicjzhattqolmclqnotctcsliyvjwutvrtrhichssehtlwbrq
123
 cznjenwypyeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjsqzhrjddauttbxphfzljgbvcqshateqeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjs
41
 ezlrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhzoeptxwaunvarfcapxsnamwjyqpxbiegizqotuqen
15
 zumtumtlitf
2
 wqlvwkiiqfmesejedhyjjfgzqfmiqyaiqefzaywrdundcmbfvhdflrpvkitbltbrzedvozltptkaanbpmjvsdnpthcepfydrdlscexczxwzyatupzlxdhnezdsipeyjqmbvoavsgeuulkqkexpwpttvxeovcjrqnzdeiaatzglvwkiiqfmesejedhyjjfgzqfmiqyaiq
141
 nemtbujbscvkgxnbqboeohzfozihjvhcllfseiouggzojhqcoqrvtdsgkubiophnhahgplhtjxblicnavkayzsydmxphgfvhlllontqfpqitrpjiadpmogtqyjhqfpqitrpjiadpmogtqyjhvaopbzglvdmwzsrhtsszyengbihrrzljvofgugmjedgujhzvlebpprue
140
 skllmtqzajnzjkuflkazjku
10
 ngkdgsdxouojadjqzgxewuuyxdlxulgrblxpkyzhgmkeatmhvbdelmxxrqtsarfvotcxfuiqsxbnczbadelhxtlfwrnbisayeveiejvycllhkictyyriqseznziyurlgiejvycllhkictyyriqseznziyurlgwiubyvqfmabhstqalicamyholkqlvtjfhcfbyr
133
 uzfvkgoaimitrlfjn
43
 ijtvifbuajod
5
 cxpleheyfwu
132
 lfydqwrwevvvclkkainwxwvqf
33
 kitxizqtbzwjqldmhwpmznaoddtgqzithwvyeyuixxhlnmksmsysikftzrskbnriebbwzermgcxalwpmznaoddtgqzithwvyeyuixxhlnmksmsy
32
 uqytussdzppiuwxterrfyrwtsrkdpfzhjpeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmefkurbbcbesiwcauwmlhmfslcavsreea
41
 xaxgnvphqavbuxzkcsptsih
150
 zonkpassuptcnpeoogztfpaspwdwnmiwsxeskfajlpfswzrdcxhlzxrgddtgmnngevbiybdnwelkzonhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxattjoncmhihgxdaxixkmockynyjefvhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxatt
200
 ifglyzxttgfpcgvpfmfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjyeimsfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjy
15
 mklxokaoaxzccddmsxzc
41
 eluswgbaoqmkfymoidkripnpgmbvhydcuupfhecefgosemhverqwzxklzzacdgcrrlzdnocxmzxtiamqpxspfogqhrlsnfzdexamrkowqpqggolnrvxfhenedmfzngnavgnjkzsnkjjjfcgfqjuywmrt
115
 xbmrxbmrkzovhb
3
 ktkkckrzvjhdspjmtljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudqrgrihgbljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudq
57
 thdnszfpaznmjlzacpovjcvybdkynhnvkaxvncfpofvnfpkggyfvqbklvrnbwpjswbrvjvqyzheslzxvuuqpbrvjvqyzheslzxvuuqprxasesuweenacripkyevplccdlxocfuqklypxactpajkmhcsgbxwgznizwndthualdbbgxhrtdrodoiddzdmxtatssfsuksqz
23
 fonwebmlwaxthdwche
57
 pdgrwrozhkrwwgebwvuilwm
32
 jhfwjyyzwrjiyrrgveiqkoltivghgkontrqragikttxxuwszjwqhwxindyrdqhucnbwgwrppgqmsasrzohezjlfmkzsqptwpratprcrxyxecnlsaiqrvimihmhjfgzwdtvmfhgbuonpsblphyoxzclkrwbwrkasahiirzqlfjdoomlosltldbpomyyhmdwfchzxnmwlh
200
 ayi
10
 eexlzphiay
1
 auxrkguktewrcwwklhmuxkgdialidacmjinwcsrtfrtdsvqsbwuqtsrmsyizsvdkbqwrbuphqqvzktqkskylnnqbezibqnaytuuqddrigdkbqwrbuphqqvzktqkskylnnqbezi
23

64
 200
 6
 246
 220
 108
 6
 334
 280
 20
 266
 60
 10
 142
 58
 120
 134
 172
 400
 186
 60
 230
 8
 190
 46
 74
 54
 400
 12
 2
 86


import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;

public class Matrix{
	public static int max = 0;	
	public static int [][] m = new int[5][5];
	
	public static void println(Object o){
		System.out.println(o);
	}
	
	public static void print(Object o){
		System.out.print(o +" ");
	}
	
	public static void printv(Object [] v){
		for(int i = 0; i < v.length; i++)
			print(v[i]);
	}
	
	public static void print3D(double [][][] m){
		for(int i = 0; i < m.length; i++){
				println("elemento:"+i);
				for(int j = 0; j < m[i].length; j++){
					for(int k = 0; k < m[i][j].length; k++){
						print(m[i][j][k]);
					}
					println("");
				}
			}
	}
	
	public static long factorial(int n){
		long ans = 1;
		for( int i = 1; i <= n; i++){
			ans += i;
		}
		return ans;
	}

	public static boolean isTendem(String s, int n){
		if(s.length() == 1) return false;
		if (s.length() / 2 + n <= s.length()){
			for(int i = 0; i < s.length()/2; i++){
				if(s.charAt(i) != s.charAt(i+n) &&  s.charAt(i+n) == '?') continue;
				else if(s.charAt(i) == s.charAt(i+n)) continue;
				else if (s.charAt(i) != s.charAt(i+n)) return false; 
			}
			return true;
		}
		return false;
	}
	
	public static void main(String [] args){
		   Scanner scan = new Scanner(System.in);
		   String s = scan.next();
		   int n = scan.nextInt();
		   int ans = 0;
		   for(int i =0; i < n; i++){
				s += '?';
		   }
		   for(int i = 0; i < s.length(); i++){
				String tem = "";
				for(int j = i; j < s.length(); j++){
					tem += s.charAt(j);
					int k = 1;
					while( k <= tem.length()/2){
						if(isTendem(tem,k)){
							//println(k +":"+tem + " " + ans);
							ans = Math.max(ans, 2*k);
						}
						k += 1;
					}
				}
				
		   }
		   print(ans);
	}
}

/*
 9 30
 2 6 9 4 7 5 8 9 10
 * */


/*
 public static double expectedCells(int N) { 
        double[][][] prob = new double[2][N + 2][N + 1];
        int old = 0, ne = 1; 
        prob[old][1][0] = 1;
        print3D(prob);
        println("----------Inicio----------");  
        for (int i = 0; i < N; ++i) { 
            for (double[] a : prob[ne]) { 
                Arrays.fill(a, 0);  
            }
            println("----------"+i+"----------"); 
            print3D(prob); 
            for (int len = 1; len <= i + 1; ++len) { 
                for (int pos = 0; pos < len; ++pos) {
					println(old + " " + len +" "+pos); 
                    double cur = prob[old][len][pos]; 
                    if (pos == 0) { 
                        prob[ne][len + 1][0] += cur / 2; 
                    } else { 
                        prob[ne][len][pos - 1] += cur / 2; 
                    } 
                    if (pos == len - 1) { 
                        prob[ne][len + 1][pos + 1] += cur / 2; 
                    } else { 
                        prob[ne][len][pos + 1] += cur / 2; 
                    } 
                } 
            } 
            old ^= 1; 
            ne ^= 1; 
        } 
		double res = 0; 
        for (int len = 1; len <= N + 1; ++len) { 
            for (int pos = 0; pos < len; ++pos) { 
                res += prob[old][len][pos] * len; 
            } 
        } 
		return res; 
	} 
	* 
	* 
	*  Scanner scan = new Scanner(System.in);
			String s = scan.nextLine();
			HashSet <String> set = new HashSet<String>();
			for(int i = 0  ; i < s.length(); i++)
				if(s.charAt(i) != ' ' && s.charAt(i) != ',' && s.charAt(i) != '{' && s.charAt(i) != '}' ){
					set.add(s.charAt(i)+"");
				}
			print(set.size());
*/
