#include <bits/stdc++.h>
const int N = 205;
char s[N];
int n, K, ans, flag[N << 1];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1), scanf("%d", &K);
  for (int k = 1; k * 2 <= n + K; ++k) {
    for (int i = 1; i + k <= n + K; ++i)
      flag[i] = i + k > n || s[i] == s[i + k];
    for (int l = 0, r = 1; r + k <= n + K; ++r) {
      if (!flag[r]) l = r;
      if (r - l >= k) ans = k * 2;
    }
  }
  printf("%d\n", ans);
}
