#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, p, temp, t, n, ans, caseno = 0;
  string str;
  while (cin >> str >> k) {
    ans = 0;
    l = str.size();
    for (i = 0; i < l + k; i++) {
      for (j = i; j <= l - 1 + k; j++) {
        temp = j - i + 1;
        if (temp % 2) continue;
        temp /= 2;
        bool flag = true;
        for (p = 0; p < temp; p++) {
          if (i + p >= l || i + p + temp >= l) break;
          if (str[i + p] != str[i + p + temp]) {
            flag = false;
            break;
          }
        }
        if (flag) ans = max(2 * temp, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
