#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k, t(0), m(0);
  cin >> k;
  for (int i = 0; i < k; i++) s += '?';
  for (int i = 0; i < s.length(); i++)
    for (int j = i; j < s.length(); j++) {
      bool ok = true;
      for (int k = i; k <= j; ++k) {
        if (j + 1 + k - i >= s.length()) {
          ok = false;
          break;
        }
        char c1 = s[k], c2 = s[j + 1 + k - i];
        if (!((c1 == c2) || c1 == '?' || c2 == '?')) ok = false;
      }
      if (ok == true) t = max(t, j - i + 1);
    }
  cout << t * 2;
  return 0;
}
