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
/*
Keep solving problems.
*/

import java.util.*;
import java.io.*;

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    int n;
    char[][] arr;
    long res = 0;
    long single = 0;
    boolean isSingle = true;
    char left;
    char right;
    long pref = 0;
    long suff = 0;
    void solve() throws IOException {
        n = nextInt();
        arr = new char[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextString().toCharArray();
        }

        precomp();

        for (int i = n - 2; i >= 0; i--) {
            merge(i);
        }

        outln(res);
    }

    void merge(int cur) {
        if (isSingle) {
            if (checkSingle(cur)) {
                if (arr[cur][0] == left) {
                    single = single * (arr[cur].length + 1) + arr[cur].length;
                    pref = single;
                    suff = single;
                }
                else {
                    isSingle = false;
                }
            }
        }
        else {
            for (char c : arr[cur]) {
                if (left == c) {
                    if (right == c) {
                        single = Math.max(single, pref + suff + 1);
                    }
                    else {
                        single = Math.max(single, pref + 1);
                    }
                }
                else {
                    if (right == c) {
                        single = Math.max(single, suff + 1);
                    }
                }
            }
        }

        res = Math.max(res, single);
    }

    boolean checkSingle(int idx) {
        for (int i = 1; i < arr[idx].length; i++) {
            if (arr[idx][i] != arr[idx][0]) {
                return false;
            }
        }

        return true;
    }

    void precomp() {
        int sz = arr[n - 1].length;
        isSingle = checkSingle(n - 1);

        int start = 0;
        while (start < sz) {
            int end = start;
            while (end < sz && arr[n - 1][end] == arr[n - 1][start]) {
                end++;
            }

            single = Math.max(single, end - start);
            start = end;
        }

        res = Math.max(res, single);

        left = arr[n - 1][0];
        right = arr[n - 1][sz - 1];
        if (isSingle) {
            pref = sz;
            suff = sz;
            return;
        }

        start = 0;
        while (arr[n - 1][start] == left) {
            start++;
        }

        pref = start;
        start = n - 1;
        while (arr[n - 1][start] == right) {
            start--;
        }

        suff = n - 1 - start;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        outln(String.format("%.9f%n", val));
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}