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.Scanner;

public class Main {
	// Just run correctly, God damn it!!
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan = new Scanner(System.in);
		String input = scan.next();
		String inputTmp = input;
		int k = scan.nextInt();

		int len = input.length();

		for (int i = 0; i < k; i++)
			input += "#";
		int maxi = 0;
		if (len <= k) {
			maxi = (len + k) / 2 * 2;
			System.out.println(maxi);
			return;
		}

		for (int i = 0; i < input.length(); i++) {

			int count = 0;
			int j = i;
			int n = (int) Math.ceil(input.substring(i).length() / 2.0);
			while (j < input.length() - n
					&& (input.charAt(j) == input.charAt(j + n) || input
							.charAt(j + n) == '#')) {
				// System.out.println(input.charAt(j) + " " + input.charAt(j +
				// n));
				count++;
				j++;
			}
			// if(i!=j)i = j-1;
			// else
			// i = j;

			maxi = count > maxi ? count : maxi;

		}

	//	System.out.println(2 * maxi);

		// check within the string itself
		for (int i = 0; i < inputTmp.length() - 1; i++) {

			int j = i;
			String tmp = "";
			String theRest = inputTmp.substring(i + 1);

			while (j < inputTmp.length()
					&& theRest.contains(tmp + inputTmp.charAt(j))) {

				tmp += inputTmp.charAt(j);
				theRest = theRest.substring(1);
				j++;
			}
			// if(j!=i)i = j-1;

			maxi = Math.max(maxi, tmp.length());
			// System.out.println("--->"+tmp.length()*2);
		}

		// System.out.println(2*k);
		// check the hashes as well
		// maxi = k > maxi ? k : maxi;

		System.out.println(2 * maxi);

	}
}