#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const long long oo = 1000;
int ans;
string s;
int k;
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  cin >> k;
  for (int i = 1; i <= k; i++) s = s + '*';
  int len = s.size();
  for (int k = 1; k <= len; k++)
    for (int i = 0; i < len; i++) {
      if (i + k * 2 > len) continue;
      bool ok = 1;
      for (int j = 0; j < k; j++)
        if (s[i + j] != s[i + j + k] && s[i + j] != '*' &&
            s[i + j + k] != '*') {
          ok = 0;
          break;
        }
      if (ok)
        if (ok) ans = max(k * 2, ans);
    }
  cout << ans;
}
