N = int(input()) S = [] for _ in range(N): s = input() l = list(s) if l == sorted(l): S.append(s) S.sort(key=lambda x: x[-1]) ans = 0 t = 'a' for s in S: if t <= s[0]: ans += len(s) t = s[-1] print(ans)