#include <bits/stdc++.h>
using namespace std;
const long long N = 205;
string str;
bool check(long long idx, long long n) {
  for (long long i = idx; i < idx + n; i++) {
    if (str[i + n] == '?') return true;
    if (str[i] != str[i + n]) return false;
  }
  return true;
}
int main() {
  long long n, m, k, i, j;
  cin >> str >> k;
  str += string(k, '?');
  n = str.size();
  for (i = n / 2; i >= 0; i--) {
    for (j = 0; j + 2 * i <= n; j++) {
      if (check(j, i)) {
        cout << 2 * i << "\n";
        return 0;
      }
    }
  }
  return 0;
}
