az = 'abcdefghijklmnopqrstuvwxyz'

N = int(input())
S = [input() for _ in range(N)]

S.sort()

dp = {chr(ord('a') - 1): 0}

for l in S:
    if ''.join(sorted(l)) != l:
        continue
    lc = l[-1]
    for c in reversed(az):
        if c not in dp:
            continue
        if l[0] < c:
            continue
        dp.setdefault(lc, 0)
        dp[lc] = max(dp[lc], dp[c] + len(l))
    dp.setdefault(lc, 0)
    dp[lc] = max(dp[lc], len(l))
print(max(dp.values()))