from bisect import bisect_right n=int(input().split()) memo=[] for _ in range(n): memo.append(input()) memo.sort() m=''.join(memo) infi=1<<40 dp=[infi]*(2*10**5+100) dp[0]=-infi for i in range(len(m)): s=ord(m[i])-ord('a') pos = bisect_right(dp,s) dp[pos]=s ans= bisect_right(dp,infi-1) print(ans)