n = int(input())
wordlist = []
d = {}
for i in range(n):
s = input()
wordlist += [s]
d[s] = 0
def h(loong, dic, length):
m = len(loong)
for i in range(n):
temdic = dic
if dic[wordlist[i]] < 2:
for j in range(min(len(wordlist[i]), length) - 1, 0, -1):
if loong[-j:] == wordlist[i][:j]:
temdic[wordlist[i]] += 1
m = max(m, h(loong[:-j] + wordlist[i], temdic, len(wordlist[i]) - j))
break
print(loong)
return m
l = input()
t = 0
for i in range(n):
if wordlist[i][0] == l:
t = max(t, h(wordlist[i], d, len(wordlist[i])))
print(t)