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>
#pragma optimize(3)
using namespace std;
const long long LLMAX = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
template <class T>
inline void read(T &DataIn) {
  DataIn = 0;
  T Flag = 0;
  char c = getchar();
  while (!isdigit(c)) {
    Flag |= c == '-';
    c = getchar();
  }
  while (isdigit(c)) {
    DataIn = DataIn * 10 + c - '0';
    c = getchar();
  }
  DataIn = Flag ? -DataIn : DataIn;
}
template <class T>
inline void write(T DataOut, char EndChar = '\n') {
  T lenth = 0, number[30];
  if (DataOut == 0) {
    putchar(48);
    return;
  }
  while (DataOut > 0) {
    number[++lenth] = DataOut % 10;
    DataOut /= 10;
  }
  for (int i = lenth; i >= 1; i--) putchar(number[i] + 48);
  putchar(EndChar);
}
priority_queue<int, vector<int>, less<int> > qd;
priority_queue<int, vector<int>, greater<int> > qu;
long long len[30];
int main(void) {
  FILE *fin = NULL, *fout = NULL;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long pre = 0, ida = s[0] - 'a', suf = 0, idb = s[s.size() - 1] - 'a';
    for (int j = 0; j < s.size(); j++)
      if (s[j] - 'a' == ida)
        pre++;
      else
        break;
    for (int j = s.size() - 1; j >= 0; j--)
      if (s[j] - 'a' == idb)
        suf++;
      else
        break;
    if (pre == s.size()) {
      len[ida] = (len[ida] + 1) * pre + len[ida];
      if (len[ida] > 0x3f3f3f3f) len[ida] = 1;
      for (int j = 0; j < 26; j++)
        if (j != ida) len[j] = min(len[j], 1ll);
      continue;
    }
    for (int j = 0; j < 26; j++) len[j] = min(len[j], 1ll);
    if (ida == idb && len[ida] == 0)
      len[ida] = max(suf, pre);
    else
      len[ida] += pre, len[idb] += suf;
    s = s + "1";
    for (long long j = 1, cnt = 1; j < s.size(); j++)
      if (s[j] == s[j - 1])
        cnt++;
      else {
        len[s[j - 1] - 'a'] = max(len[s[j - 1] - 'a'], cnt);
        cnt = 1;
      }
  }
  for (int i = 0; i < 26; i++) ans = max(ans, len[i]);
  cout << ans << endl;
  return 0;
}
