#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n;
  cin >> s;
  scanf("%d", &n);
  string tmp = "";
  for (int i = 0; i < n; i++) tmp += "&";
  for (int i = 0; i < 10000000; i++)
    ;
  s = s + tmp;
  int ans = 0;
  int d;
  int k = s.length();
  for (ans = k / 2; ans > 0; ans--) {
    for (int i = 0; i < k - ans + 1; i++) {
      d = 0;
      for (int j = i; j < i + ans; j++) {
        if (s[j + ans] != '&' && s[j] != s[j + ans]) {
          d = 1;
          break;
        }
      }
      if (d == 0) {
        printf("%d\n", ans * 2);
        return 0;
      }
    }
  }
  printf("0\n");
  return 0;
}
