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.IOException;
import java.io.FilterInputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		JoltyScanner in = new JoltyScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TandemRepeat solver = new TandemRepeat();
		solver.solve(1, in, out);
		out.close();
	}
}

class TandemRepeat {
    public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
        StringBuilder str = new StringBuilder(in.next());

        int wild = in.nextInt();
        for (int i = 0; i < wild; i++) {
            str.append("?");
        }

        char[] arr = str.toString().toCharArray();
        int result = 0;
        for (int start = 0; start + result + result <= arr.length; start++) {
            Width: for (int width = result + 1; start + width + width <= arr.length; width++) {
                for (int idx = 0; idx < width; idx++) {
                    if (arr[start + idx] != arr[start + width + idx] && arr[start + width + idx] != '?') {
                        continue Width;
                    }
                }
                result = width;
            }
        }

        out.println(result << 1);
    }
}

class JoltyScanner {
    public static final int BUFFER_SIZE = 1 << 16;
    public static final char NULL_CHAR = (char) -1;

    StringBuilder str = new StringBuilder();
    byte[] buffer = new byte[BUFFER_SIZE];
    boolean EOF_FLAG = false;
    int bufferIdx = 0, size = 0;
    char c = (char) -1;
    BufferedInputStream in = new BufferedInputStream(System.in, BUFFER_SIZE);
    public JoltyScanner(InputStream in) {
        this.in = new BufferedInputStream(in);
    }
    public int nextInt() {
        long x = nextLong();
        if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {
            throw new ArithmeticException("Scanned value overflows integer");
        }
        return (int) x;
    }
    public long nextLong() {
        boolean negative = false;
        if (c == NULL_CHAR) {
            c = nextChar();
        }
        while (!EOF_FLAG && (c < '0' || c > '9')) {
            if (c == '-') {
                negative = true;
            }
            c = nextChar();
        }
        if (EOF_FLAG) {
            throw new EndOfFileException();
        }
        long res = 0;
        while (c >= '0' && c <= '9') {
            res = (res << 3) + (res << 1) + c - '0';
            c = nextChar();
        }
        return negative ? -res : res;
    }

    public String next() {
        if (EOF_FLAG) {
            throw new EndOfFileException();
        }
        if (c == NULL_CHAR) {
            c = nextChar();
        }
        while (!EOF_FLAG && Character.isWhitespace(c)) {
            c = nextChar();
        }
        str.setLength(0);
        while (!EOF_FLAG && !Character.isWhitespace(c)) {
            str.append(c);
            c = nextChar();
        }
        return str.toString();
    }
    public char nextChar() {
        if (EOF_FLAG) {
            return NULL_CHAR;
        }
        while (bufferIdx == size) {
            try {
                size = in.read(buffer);
                if (size == -1) {
                    throw new Exception();
                }
            }
            catch (Exception e) {
                EOF_FLAG = true;
                return (char) -1;
            }
            if (size == -1) {
                size = BUFFER_SIZE;
            }
            bufferIdx = 0;
        }
        return (char) buffer[bufferIdx++];
    }

    public class EndOfFileException extends RuntimeException {}
}

