#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  int ns = s.size();
  int n = ns + k - (ns + k) % 2;
  if (k >= ns)
    cout << n << endl;
  else {
    int res = 0;
    for (int l = 0; l < ns; ++l)
      for (int len = 1; l + len - 1 < ns; ++len) {
        int r = l + len - 1, cnt = 0;
        for (int u = l; u <= r; ++u)
          if (u + len >= ns && u + len < ns + k)
            ++cnt;
          else if (s[u] == s[u + len])
            ++cnt;
        if (cnt == len && 2 * cnt > res) res = 2 * cnt;
      }
    cout << res << endl;
  }
  return 0;
}
