#include <bits/stdc++.h>
using namespace std;
string s;
int k, ls;
int main() {
  cin >> s >> k;
  int lim, i, j, n, p, l = s.size();
  int mx = 0;
  for (i = 0; i < k; i++) {
    s = s + "*";
  }
  for (i = 1; i <= s.size(); i++) {
    for (j = 0; j + 2 * i <= s.size(); j++) {
      for (k = j, p = 0; p < i; p++, k++) {
        if (s[k] == s[k + i]) continue;
        if (s[k + i] == '*') continue;
        break;
      }
      if (p == i) {
        mx = max(mx, 2 * i);
      }
    }
  }
  cout << mx << "\n";
  return 0;
}
