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;
class Node {
 public:
  Node() {
    l = r = lcnt = rcnt = 0;
    memset(f, 0, sizeof f);
  }
  Node(const Node& a) {
    l = a.l;
    r = a.r;
    lcnt = a.lcnt;
    rcnt = a.rcnt;
    for (int i = 0; i < 26; i++) f[i] = a.f[i];
  }
  char l, r;
  int lcnt, rcnt, type;
  int f[26];
  void clear() {
    l = r = lcnt = rcnt = 0;
    memset(f, 0, sizeof f);
  }
} ret;
void gao(string& s) {
  int n = s.length();
  ret.clear();
  ret.l = s[0];
  int pos = 0;
  while (pos < n && s[pos] == ret.l) ++pos, ret.lcnt++;
  if (ret.lcnt == n)
    ret.type = 0;
  else
    ret.type = 1;
  ret.r = s[n - 1];
  pos = n - 1;
  while (pos >= 0 && s[pos] == ret.r) pos--, ret.rcnt++;
  char pre = s[0];
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      ret.f[pre - 'a'] = max(ret.f[pre - 'a'], cnt);
      pre = s[i];
      cnt = 1;
    } else {
      cnt++;
    }
  }
  ret.f[pre - 'a'] = max(ret.f[pre - 'a'], cnt);
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  gao(s);
  Node ans = ret;
  for (int i = 1; i < n; i++) {
    cin >> s;
    gao(s);
    if (ans.type == 0 && ret.type == 0) {
      if (ans.l == ret.l) {
        ans.lcnt += (ans.lcnt + 1) * s.length();
        ans.f[ans.l - 'a'] = ans.lcnt;
      } else {
        char a = ans.l;
        ans = ret;
        ans.f[a - 'a'] = 1;
        ans.type = 1;
      }
    } else if (ans.type == 1 && ret.type == 0) {
      if (ans.l == ret.l) {
        ans.lcnt += (ans.lcnt + 1) * s.length();
      } else {
        ans.lcnt = s.length();
        ans.l = s[0];
      }
      if (ans.r == ret.l) {
        ans.rcnt += (ans.rcnt + 1) * s.length();
      } else {
        ans.rcnt = s.length();
        ans.r = s[0];
      }
      for (int i = 0; i < 26; i++) {
        if (i == s[0] - 'a') {
          ans.f[i] += (ans.f[i] + 1) * s.length();
        } else {
          ans.f[i] = ans.f[i] > 0;
        }
      }
    } else {
      ans.l = ret.l;
      ans.lcnt = ret.lcnt;
      ans.r = ret.rcnt;
      ans.rcnt = ret.rcnt;
      for (int i = 0; i < 26; i++) {
        if (ans.f[i] == 0) continue;
        if (i == ret.r - 'a') {
          ans.f[i] = ret.rcnt + 1;
          if (i == ret.l - 'a') {
            ans.f[i] += ret.lcnt;
          }
        } else if (i == ret.l - 'a') {
          ans.f[i] = ret.lcnt + 1;
        } else {
          ans.f[i] = 1;
        }
      }
      for (int i = 0; i < 26; i++) ans.f[i] = max(ans.f[i], ret.f[i]);
    }
  }
  int mx = -1;
  for (int i = 0; i < 26; i++) mx = max(mx, ans.f[i]);
  cout << mx << endl;
}
