9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
n = int(input())
d = dict()
for i in range(26):
    d[i] = 0

for i in range(n):
    a = list(input())
    pos = 0
    pref = 0
    lets = set()
    while pos < len(a):
        j = pos
        lets.add(a[pos])
        while j < len(a) and a[j] == a[pos]:
            j += 1
        if pos == 0 and j == len(a):
            #print('here')
            d[ord(a[pos]) - ord('a')] = (d[ord(a[pos]) - ord('a')] + 1) * len(a) + d[ord(a[pos]) - ord('a')]
        elif pos == 0:
            plus = 0
            if d[ord(a[pos]) - ord('a')] != 0:
                plus = 1
            pref = j - pos
            d[ord(a[pos]) - ord('a')] = pref + plus
            # print(pref, d[ord(a[pos]) - ord('a')])
        elif j == len(a):
            plus = 0
            if a[0] == a[-1]:
                plus = min(1, max(d[ord(a[pos]) - ord('a')] - pref, 0))
                if d[ord(a[pos]) - ord('a')] - pref > 0:
                    plus += pref
            elif d[ord(a[pos]) - ord('a')] > 0:
                plus = 1
            #print('j', plus, d[ord(a[pos]) - ord('a')], a[pos])
            d[ord(a[pos]) - ord('a')] = j - pos + plus
        else:
            d[ord(a[pos]) - ord('a')] = j - pos
        pos = j
    #print(d.values())

    for pos in range(26):
        if chr(pos + ord('a')) not in lets:
            d[pos] = min(1, d[pos])

ans = max(d.values())
# print(d.values())
print(ans)