#include <bits/stdc++.h>
using namespace std;
char a[205];
int judge(int n, int m, int ans) {
  for (int k = n + m - 2 * ans; k >= 0; k--) {
    int flag = 0;
    for (int i = k, j = i + ans; j < n && i < k + ans; i++, j++) {
      if (a[i] != a[j]) {
        flag = 1;
      }
    }
    if (flag == 0) {
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%s", a);
  int n = strlen(a);
  int m;
  scanf("%d", &m);
  if (n <= m) {
    int ans = (n + m) / 2 * 2;
    printf("%d\n", ans);
  } else {
    int ans = (n + m) / 2;
    int i = 0;
    int sum = 0;
    for (int i = ans; i > m; i--) {
      if (judge(n, m, i) == 1) {
        sum = i;
        break;
      }
    }
    sum = max(sum, m);
    sum = 2 * sum;
    printf("%d\n", sum);
  }
}
