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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class E_StringMultiplication {

	static boolean isOneCharacter(String s) {
		if(s.length()>=1) {
			char tmp=s.charAt(0);
			for(int i=1;i<s.length();i++) {
				if(s.charAt(i)!=tmp) {
					return false;
				}
			}
			return true;
		}else {
			return false;
		}
	} 



	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String p[]=new String[n];
		for(int i=0;i<n;i++) {
			p[i]=br.readLine();
		}
		int LongestCont[]=new int[26];
		for(String pp:p) {

			if(isOneCharacter(pp)) {
				for(int i=0;i<26;i++) {
					if(i!=pp.charAt(0)-'a') {
						LongestCont[i]=Math.min(1, LongestCont[i]);
					}else {
						LongestCont[i]=pp.length()*(LongestCont[i]+1)+LongestCont[i];
					}
				}
			}else {
				for(int i=0;i<26;i++) {
					LongestCont[i]=Math.min(LongestCont[i],1);
				}

				char start_char=pp.charAt(0);
				char end_char=pp.charAt(pp.length()-1);
				int start_count=1;
				int end_count=1;
				int i_start,i_end;
				for(i_start=1;i_start<pp.length();i_start++) {
					if(pp.charAt(i_start)==start_char) {
						start_count++;
					}else {
						break;
					}
				}
				for(i_end=pp.length()-2;i_end>0;i_end--) {
					if(pp.charAt(i_end)==end_char) {
						end_count++;
					}else {
						break;
					}
				}
				if(start_char==end_char) {
					if(LongestCont[start_char-'a']==0) {
						LongestCont[start_char-'a']=Math.max(start_count, end_count);
					}else {
						LongestCont[start_char-'a']=start_count+end_count+1;
					}
				}else {
					LongestCont[start_char-'a']+=start_count;
					LongestCont[end_char-'a']+=end_count;

				}


//				System.out.println(i_start+","+i_end);
				int middle_start=i_start;
				for(int i=i_start;i<=i_end;i++) {
					if(pp.charAt(i)==pp.charAt(i+1)) {
						continue;
					}else {
						int count=i+1-middle_start;
						LongestCont[pp.charAt(i)-'a']=Math.max(LongestCont[pp.charAt(i)-'a'],count);
						middle_start=i+1;
					}
				}


				//				if(i_start==i_end) {
				//					LongestCont[start_char-'a']=LongestCont[start_char-'a']+start_count;
				//					maxCont[end_char-'a']=maxCont[end_char-'a']+end_count;
				//					
				//				}else {
				//					char middle_char=pp.charAt(i_start);
				//					int middle_count=0;
				//					int start_in_middle=0;
				//					int end_in_middle=0;
				//					int se_in_middle=0;
				//					for(int i=i_start;i<=i_end+1;i++) {
				//						if(pp.charAt(i)==middle_char) {
				//							middle_count++;
				//						}else {
				//							if(middle_char!=start_char && middle_char!=end_char) {
				//								maxCont[middle_char-'a']=Math.max(maxCont[middle_char-'a'],middle_count);
				//							}else if(middle_char==start_char && middle_char==end_char) {
				//								se_in_middle=Math.max(se_in_middle, middle_count);
				//							}else if(middle_char==start_char) {
				//								start_in_middle=Math.max(start_in_middle, middle_count);
				//							}else if(middle_char==end_char) {
				//								end_in_middle=Math.max(end_in_middle, middle_count);
				//							}else {
				//
				//							}
				//							middle_char=pp.charAt(i);
				//							middle_count=1;
				//						}
				//					}
				//					//					maxCont[middle_char-'a']=Math.max(maxCont[middle_char-'a'],middle_count);
				//					if(start_char==end_char) {
				//						if(maxCont[start_char-'a']==0) {
				//							maxCont[start_char-'a']=Math.max(start_count, end_count);
				//						}else {
				//							maxCont[start_char-'a']=Math.max(start_count+end_count+1, se_in_middle);
				//						}
				//					}else {
				//						maxCont[start_char-'a']=Math.max(start_in_middle, start_count+maxCont[start_char-'a']);
				//						maxCont[end_char-'a']=Math.max(end_in_middle, end_count+maxCont[end_char-'a']);
				//					}
				//				}
				//			}

//				for(int i=0;i<26;i++) {
//					System.out.print((char)(i+'a')+" ");
//				}
//				System.out.println();
//				for(int i=0;i<26;i++) {
//					System.out.print(LongestCont[i]+" ");
//				}
//				System.out.println();

			}


			
		}
		int maxBeauty=0;
		for(int i=0;i<26;i++) {
			maxBeauty=Math.max(maxBeauty, LongestCont[i]);
		}
		System.out.println(maxBeauty);



		br.close();
	}
}