#include <bits/stdc++.h>
using namespace std;
char s[205];
int main() {
  int n;
  scanf("%s%d", s, &n);
  int len = strlen(s);
  int L = len + n - (len + n) % 2;
  if (len <= n)
    printf("%d\n", L);
  else {
    int maxlen = 0;
    for (int i = 0; i < len; i++) {
      for (int j = 1; i + j - 1 <= len - 1; j++) {
        int num = 0;
        for (int k = i; k <= i + j - 1; k++) {
          if (len <= k + j && k + j < len + n)
            num++;
          else if (s[k] == s[k + j])
            num++;
        }
        if (num == j && 2 * num > maxlen) maxlen = 2 * num;
      }
    }
    printf("%d\n", maxlen);
  }
  return 0;
}
