#include <bits/stdc++.h>
using namespace std;
string s;
int k;
int ans = 0;
int main() {
  cin >> s >> k;
  for (int i = 0; i < k; ++i) s += '?';
  int n = (int)s.length();
  for (int left = 0; left < n; ++left) {
    for (int right = left + 1; right < n; ++right) {
      int len = right - left + 1;
      if (len % 2 == 1) continue;
      bool isTandem = true;
      for (int i = left; i < left + len / 2; ++i) {
        if (s[i] != s[i + len / 2] && s[i] != '?' && s[i + len / 2] != '?')
          isTandem = false;
      }
      if (isTandem) ans = max(ans, len);
    }
  }
  cout << ans;
  return 0;
}
