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
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = false;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = true;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int n;
int ex[30];
int main() {
  read(n);
  string s;
  cin >> s;
  int l = s.length(), i;
  s = " " + s;
  char c;
  int d = 0;
  for (i = 1; i <= l; i++) {
    if (s[i] != s[i - 1]) {
      if (i != 1) ex[c - 96] = max(ex[c - 96], d);
      d = 1;
      c = s[i];
    } else
      d++;
  }
  ex[c - 96] = max(ex[c - 96], d);
  bool lg;
  int j, st, ed;
  for (j = 2; j <= n; j++) {
    cin >> s;
    l = s.length();
    s = " " + s;
    lg = true;
    for (i = 2; i <= l; i++)
      if (s[i] != s[i - 1]) {
        lg = false;
        break;
      }
    if (lg) {
      d = ex[s[1] - 96];
      for (i = 1; i <= 26; i++)
        if (ex[i] != 0)
          ex[i] = 1;
        else
          ex[i] = 0;
      if (d)
        ex[s[1] - 96] = l * (d + 1) + d;
      else
        ex[s[1] - 96] = l;
    } else {
      st = 1;
      for (i = 2; i <= l; i++)
        if (s[i] != s[i - 1])
          break;
        else
          st++;
      ed = 1;
      for (i = l - 1; i >= 1; i--)
        if (s[i] != s[i + 1])
          break;
        else
          ed++;
      for (i = 1; i <= 26; i++)
        if (ex[i] != 0)
          ex[i] = 1;
        else
          ex[i] = 0;
      if (s[1] == s[l]) {
        if (ex[s[1] - 96] != 0)
          ex[s[1] - 96] = st + ed + 1;
        else
          ex[s[1] - 96] = max(st, ed);
      } else {
        if (ex[s[1] - 96] != 0)
          ex[s[1] - 96] = st + 1;
        else
          ex[s[1] - 96] = st;
        if (ex[s[l] - 96] != 0)
          ex[s[l] - 96] = ed + 1;
        else
          ex[s[l] - 96] = ed;
      }
      for (i = 1; i <= l; i++) {
        if (s[i] != s[i - 1]) {
          if (i != 1) {
            ex[c - 96] = max(ex[c - 96], d);
            d = 1;
            c = s[i];
          }
        } else
          d++;
      }
      ex[c - 96] = max(ex[c - 96], d);
    }
  }
  int res = 0;
  for (i = 1; i <= 26; i++) res = max(res, ex[i]);
  writeln(res);
  return 0;
}
