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 E
{

	static FastIO f;

	public static void main(String args[]) throws IOException
	{
		f = new FastIO();

		int n = f.ni(), i, j, r, fo, b;
		char[] p = f.nca();
		long c[], k = 0, l = 0;

		c = count(p, new long[26]);

		for(i = 1; i < n; i++)
		{
			// f.err(Arrays.toString(c) + "\n");
			p = f.nca();
			for(j = 1, k = 1; j < p.length && p[j] == p[j-1]; j++, k++);
			if(j == p.length)
			{
				r = p[0] - 'a';
				k *= (c[r]+1);
				k += c[r];
				fo = b = -1;
			}
			else
			{
				r = -1;
				fo = p[0] - 'a';
				b = p[p.length-1] - 'a';
				for(j = 1, k = 1; j < p.length && p[j] == p[j-1]; j++, k++);
				for(j = p.length-2, l = 1; j >= 0 && p[j] == p[j+1]; j--, l++);
				if(fo == b)
				{
					b = -1;
					k = k+l+1;
					if(c[fo] == 0)
						fo = -1;
				}
				else
				{
					if(c[fo] == 0)
						fo = -1;
					else
						k++;

					if(c[b] == 0)
						b = -1;
					else
						l++;
				}
			}

			c = count(p, c);
			if(r != -1)
			{
				c[r] = k;
			}

			if(fo != -1)
			{
				c[fo] = k;
			}

			if(b != -1)
			{
				c[b] = l;
			}
		}
		// f.err(Arrays.toString(c) + "\n");

		for(i = 0, k = -1; i < 26; i++)
			k = Math.max(k, c[i]);

		f.out(k + "\n");

		f.flush();
	}

	public static long[] count(char[] p, long[] pc)
	{
		long c[] = new long[26], j;
		int i;

		for(i = 0; i < 26; i++)
			if(pc[i] != 0)
				c[i] = 1;

		for(i = 1, j = 1; i < p.length; i++)
		{
			if(p[i] == p[i-1])
				j++;
			else
			{
				c[p[i] - 'a'] = Math.max(c[p[i] - 'a'], j);
				j = 1;
			}
		}
		c[p[i-1] - 'a'] = Math.max(c[p[i-1] - 'a'], j);

		return c;
	}

	public static class FastIO
	{
		BufferedReader br;
		BufferedWriter bw, be;
		StringTokenizer st;

		public FastIO()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
			bw = new BufferedWriter(new OutputStreamWriter(System.out));
			be = new BufferedWriter(new OutputStreamWriter(System.err));
			st = new StringTokenizer("");
		}

		private void read() throws IOException
		{
			st = new StringTokenizer(br.readLine());
		}

		public String ns() throws IOException
		{
			while(!st.hasMoreTokens())
				read();
			return st.nextToken();
		}

		public int ni() throws IOException
		{
			return Integer.parseInt(ns());
		}

		public long nl() throws IOException
		{
			return Long.parseLong(ns());
		}

		public float nf() throws IOException
		{
			return Float.parseFloat(ns());
		}

		public double nd() throws IOException
		{
			return Double.parseDouble(ns());
		}

		public char nc() throws IOException
		{
			return ns().charAt(0);
		}

		public int[] nia(int n) throws IOException
		{
			int[] a = new int[n];
			for(int i = 0; i < n; i++)
				a[i] = ni();

			return a;
		}

		public long[] nla(int n) throws IOException
		{
			long[] a = new long[n];
			for(int i = 0; i < n; i++)
				a[i] = nl();

			return a;
		}

		public char[] nca() throws IOException
		{
			return ns().toCharArray();
		}

		public void out(String s) throws IOException
		{
			bw.write(s);
		}

		public void flush() throws IOException
		{
			bw.flush();
			be.flush();
		}

		public void err(String s) throws IOException
		{
			be.write(s);
		}
	}
}