#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, p, mx = 0, t, tr;
  string s;
  cin >> s >> p;
  for (i = 1; i <= p; i++) s += "#";
  for (i = 0; i < s.size(); i++)
    for (j = 1; j * 2 + i <= s.size(); j++) {
      tr = 1;
      for (t = i; t < i + j; t++)
        if (s[t] != s[t + j] && s[t + j] != '#') {
          tr = 0;
          break;
        }
      if (tr) mx = max(mx, j * 2);
    }
  cout << mx << endl;
  return 0;
}
