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.io.*;
import java.util.*;
import java.math.BigInteger;
import java.util.Collections.*;
import static java.lang.Math.*;
import static java.lang.Math.min;
import static java.util.Arrays.*;
import static java.math.BigInteger.*;


public class TaskD2{

    void run(){
        Locale.setDefault(Locale.US);
        boolean my;
        try {
            my = System.getProperty("MY_LOCAL") != null;
        } catch (Exception e) {
            my = false;
        }
        try{
            err = System.err;
            if( my ){
                sc  = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//                sc  = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt")));
                out = new PrintWriter   (new FileWriter("output.txt"));
            }
            else {
                sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            out = new PrintWriter(new OutputStreamWriter(System.out));
        }catch(Exception e){
            MLE();
        }
        if( my )
            tBeg = System.currentTimeMillis();
        solve();
        if( my )
            err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        exit(0);
    }

    void exit( int val ){
        err.flush();
        out.flush();
        System.exit(val);
    }

    double tBeg;
    FastScanner sc;
    PrintWriter out;
    PrintStream err;

    class FastScanner{

        StringTokenizer st;
        BufferedReader br;

        FastScanner( BufferedReader _br ){
            br = _br;
        }

        String readLine(){
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        String next(){
            while( st==null || !st.hasMoreElements() )
                st = new StringTokenizer(readLine());
            return st.nextToken();
        }

        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
        double nextDouble(){ return Double.parseDouble(next()); }
    }

    void MLE(){
        int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];
    }

    void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new TaskD2().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//        }, "Lolka", 256_000_000L ).run();
    }

    ////////////////////////////////////////////////////////////////


    void solve(){
        String s = sc.next();
        int k = sc.nextInt();
        for( int it = 0; it < k; it++ ){
            s += "#";
        }

        int ans = 0;
        for( int i = 0; i < s.length(); i++ ){
            for( int j = i+1; j < s.length(); j+=2 ){
                if( isTan(s.substring(i, j + 1)) ){
                    ans = max( ans, j - i + 1 );
                }
            }
        }
        out.println( ans );
    }

    private boolean isTan(String s) {
        for( int i = 0, j = s.length()/2; i < s.length() / 2; i++, ++j ){
            if(!( s.charAt(i) == s.charAt(j) || s.charAt(j)=='#' || s.charAt(i)=='#' ) )
                return false;
        }
        return true;
    }


}