#include <bits/stdc++.h>
using namespace std;
int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; }
bool check(string str) {
  if (((int)str.length()) % 2) return 0;
  for (int i = 0; i < str.length() / 2; i++) {
    if (str[i] != str[i + str.length() / 2] && str[i] != '*' &&
        str[i + str.length() / 2] != '*')
      return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  string str;
  int k;
  cin >> str >> k;
  for (int i = 0; i < k; i++) str += "*";
  int Max = 0;
  for (int i = 0; i < str.length(); i++) {
    string temp = "";
    for (int j = i; j < str.length(); j++) {
      temp += str[j];
      if (check(temp)) Max = max(Max, (int)temp.length());
    }
  }
  cout << Max << endl;
}
