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;
const long long inf = 1e18;
const double eps = 1e-6;
string operator*(const string a, const string b) {
  string res = b;
  for (auto c : a) {
    res += c + b;
  }
  return res;
}
long long getLeft(string s) {
  char cur = s[0];
  long long cnt = 0;
  for (auto c : s) {
    if (c != cur) {
      return cnt;
    }
    cnt++;
  }
  return cnt;
}
long long getRight(string s) {
  char cur = s.back();
  long long cnt = 0;
  for (long long i = s.size() - 1; i >= 0; i--) {
    if (s[i] != cur) {
      return cnt;
    }
    cnt++;
  }
  return cnt;
}
int main() {
  long long n;
  cin >> n;
  set<char> a;
  vector<long long> cans('z' + 1, 0);
  string b;
  cin >> b;
  long long ANS = 0;
  for (auto c : b) a.insert(c);
  {
    char cur = b[0];
    long long cnt = 0;
    for (auto c : b) {
      if (c != cur) {
        cans[cur] = max(cans[cur], cnt);
        cnt = 0;
        cur = c;
      }
      cnt++;
    }
    cans[cur] = max(cans[cur], cnt);
  }
  for (long long i = 1; i < n; i++) {
    cin >> b;
    long long left = getLeft(b), right = getRight(b);
    if (left == b.size()) {
      long long ans = 1;
      for (auto c : a) {
        if (c == b.back()) {
          ans = max(ans, (cans[c] + 1) * left + cans[c]);
          cans[c] = (cans[c] + 1) * left + cans[c];
        }
      }
      ANS = max(ANS, ans);
    } else {
      long long ans = 0;
      for (auto c : a) {
        long long temp = 1;
        if (c == b.back()) temp += right;
        if (c == *b.begin()) temp += left;
        cans[c] = max(cans[c], temp);
        ans = max(ans, temp);
      }
      ANS = max(ANS, ans);
    }
    char cur = b[0];
    long long cnt = 0;
    for (auto c : b) {
      if (c != cur) {
        cans[cur] = max(cans[cur], cnt);
        cnt = 0;
        cur = c;
      }
      cnt++;
      a.insert(c);
    }
    cans[cur] = max(cans[cur], cnt);
  }
  cout << ANS;
  return 0;
}
