#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  string tmp;
  for (int i = 0; i < k; i++) {
    tmp += '+';
  }
  s += tmp;
  int maX = 0;
  int counter = 0;
  for (int t = 0; t < s.size(); t++) {
    for (int len = 1; len <= (s.size() - t) / 2; len++) {
      int cnt = 0;
      for (int j = t; cnt < len; j++) {
        if (((s[j] == s[j + len]) || s[j + len] == '+')) {
          counter++;
        }
        cnt++;
      }
      if (counter == len && len > maX) {
        maX = len;
      }
      counter = 0;
    }
  }
  cout << maX * 2;
  return 0;
}
