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
import java.util.*;
import java.io.*;
public class issam{
    public static int[] full(String s){
        int[] a = new int[26];
        int nb= 1;
        for(int i=1;i<s.length();i++){
            int c1 = s.charAt(i)-'a';
            int c2 = s.charAt(i-1) - 'a';
            if(c1==c2){
                nb++;
            }else{
                a[c2] = Math.max(nb,a[c2]);
                nb = 1;
            }
        }
        if(nb!=0) a[s.charAt(s.length()-1)-'a'] = Math.max(nb,a[s.charAt(s.length()-1)-'a']);
        return a;
    }
    public static void concat(int[] a,int[] b,int c1,int nb1,int c2,int nb2,int nb){
        int a1 = a[c1];
        int a2 = a[c2];
        for(int i=0;i<26;i++){
            a[i] = Math.max(Math.min(a[i],1),b[i]);
        }
        if(nb==nb1){
            a[c1] = a1 + (a1+1)*nb;
        }else if(c1==c2){
            if(a1!=0) a[c1] = Math.max(a1,nb1+nb2+1);
        }else{
            if(a1!=0) a[c1] = Math.max(a1,nb1+1);
            if(a2!=0) a[c2] = Math.max(a2,nb2+1);
        }
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a;
        String s = br.readLine().trim();
        a = full(s);
        for(int j=1;j<n;j++){
            s = br.readLine().trim();
            int[] b = full(s);
            int nb1=1;
            for(int i=1;i<s.length();i++){
                if(s.charAt(i)==s.charAt(i-1)) nb1++;
                else break;
            } 
            int nb2=1;
            for(int i=s.length()-2;i>=0;i--){
                if(s.charAt(i)==s.charAt(i+1)) nb2++;
                else break;
            } 
            concat(a,b,s.charAt(0)-'a',nb1,s.charAt(s.length()-1)-'a',nb2,s.length());
        }
        int max = a[0];
        for(int i=1;i<26;i++) max = Math.max(max,a[i]);
        System.out.println(max);
    }
}