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

  private static void solve() {
    int n = nextInt();

    String[] s = new String[n];

    for (int i = 0; i < n; i++) {
      s[i] = next();
    }

    int[][] c = new int[n][26];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < s[i].length(); j++) {
        c[i][s[i].charAt(j) - 'a']++;
      }
    }

    int[] l = new int[n];
    int[][] sc = new int[n][26];
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 26; j++) {
        sc[i][j] = ((i == 0 ? 0 : l[i - 1]) + 1) * c[i][j];
        sc[i][j] += (i == 0 ? 0 : sc[i - 1][j]);
        cnt += sc[i][j];
      }
      l[i] = cnt;
    }

    int ans = 0;

    for (int i = 0; i < s[n - 1].length();) {
      int j = i + 1;
      int cnt = 1;

      for (; j < s[n - 1].length() && s[n - 1].charAt(i) == s[n - 1].charAt(j); j++, cnt++);
      i = j;
      ans = Math.max(ans, cnt);
    }


    char singleChar = '0';
    for (int i = 0; i < 26; i++) {
      if (c[n - 1][i] == s[n - 1].length()) {
        singleChar = (char)('a' + i);
        break;
      }
    }

    if (singleChar != '0') {
      ans = Math.max(ans, getMax(n - 1, singleChar, sc, s, c));
    } else {
      char first = s[n - 1].charAt(0);
      int fc = 1;
      for (int i = 1; i < s[n - 1].length(); i++) {
        if (first == s[n - 1].charAt(i)) {
          fc++;
        } else {
          break;
        }
      }

      char last = s[n - 1].charAt(s[n - 1].length() - 1);
      int lc = 1;
      for (int i = s[n - 1].length() - 2; i >= 0; i--) {
        if (last == s[n - 1].charAt(i)) {
          lc++;
        } else {
          break;
        }
      }

      if (first == last) {
        if (sc[n - 2][first - 'a'] != 0) {
          ans = Math.max(ans, Math.min(fc + lc, s[n - 1].length()) + 1);
        } else {
          ans = Math.max(ans, Math.max(fc, lc));
        }
      } else {
        ans =
            Math.max(ans, Math.max(fc + (sc[n - 2][first - 'a'] == 0 ? 0 : 1), lc + (sc[n - 2][last - 'a'] == 0 ? 0 :
                1)));
      }
    }

    System.out.println(ans);
  }

  private static int getMax(int cur, char x, int[][] sc, String[] s, int[][] c) {
    int ans = 0;

    for (int i = 0; i < s[cur].length();) {
      int cnt = s[cur].charAt(i) == x ? 1 : 0;
      i++;
      for (; i < s[cur].length() && s[cur].charAt(i) == x; i++, cnt++) ;
      ans = Math.max(ans, cnt);
    }

    if (cur == 0) {
      return ans;
    }

    boolean singleChar = (c[cur][x - 'a'] == s[cur].length());

    if (singleChar) {
      int prev = getMax(cur - 1, x, sc, s, c);
      ans = Math.max(ans, (prev + 1) * s[cur].length() + prev);
    } else {
      int fc = 0;
      for (int i = 0; i < s[cur].length(); i++) {
        if (x == s[cur].charAt(i)) {
          fc++;
        } else {
          break;
        }
      }

      int lc = 0;
      for (int i = s[cur].length() - 1; i >= 0; i--) {
        if (x == s[cur].charAt(i)) {
          lc++;
        } else {
          break;
        }
      }

      ans = Math.max(ans, sc[cur - 1][x - 'a'] == 0 ? Math.max(fc, lc) : lc + fc + 1);
    }

    return ans;
  }

  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

  private static int nextInt() {
    return Integer.parseInt(next());
  }

  private static long nextLong() {
    return Long.parseLong(next());
  }

  public static void main(String[] args) {
    run();
  }
}