#include <bits/stdc++.h>
using namespace std;
string cad;
long long x, n, sol, temp;
bool IsEqual(string a, string b) {
  int n1 = a.length();
  for (int l = 0; l < n1; l++) {
    if (a[l] == b[l]) continue;
    if (a[l] == '*' || b[l] == '*') continue;
    return false;
  }
  return true;
}
int langeL(int j) {
  int psol = 0;
  bool can;
  for (int i = 1; i <= n / 2; i++) {
    if (j + i + i <= n) {
      if (IsEqual(cad.substr(j, i), cad.substr(j + i, i))) psol = i;
    }
  }
  return 2 * psol;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> cad >> x;
  for (int i = 0; i < x; i++) cad.push_back('*');
  n = cad.length();
  int sol = 0;
  for (int j = 0; j < n; j++) {
    sol = max(sol, langeL(j));
  }
  cout << sol << endl;
  return 0;
}
