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;
using namespace std::chrono;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
long long n, m, k, q, l, r, x, y, z;
long long a[1000005];
long long b[1000005];
long long c[1000005];
string second, t;
long long ans = 0;
long long top[100005][26];
long long pre[100005], suf[100005];
bool one[100005];
string ss[100005];
void solve(int tc) {
  cin >> n;
  for (long long i = 0; i < (n); ++i) {
    cin >> ss[i];
    second = ss[i];
    int sz = second.size();
    int j = 1;
    while (j < sz && second[j] == second[0]) ++j;
    pre[i] = j;
    j = sz - 2;
    while (j >= 0 && second[j] == second[sz - 1]) --j;
    suf[i] = sz - j - 1;
    one[i] = (pre[i] == sz);
    long long pt = 0;
    for (long long j = 0; j < (n); ++j) {
      if (second[j] != second[pt]) {
        top[i][second[pt] - 'a'] = max(top[i][second[pt] - 'a'], j - pt);
        pt = j;
      }
    }
    top[i][second[pt] - 'a'] = max(top[i][second[pt] - 'a'], n - pt);
  }
  for (long long i = (1); i < (n); ++i) {
    if (one[i]) {
      int p = ss[i][0] - 'a';
      top[i][p] = max(top[i][p], pre[i] * (top[i - 1][p] + 1) + top[i - 1][p]);
    }
    for (long long c = 0; c < (26); ++c)
      if (top[i - 1][c] > 0) {
        long long x = 1;
        if (ss[i][0] == c) x += pre[i];
        if (ss[i][ss[i].size() - 1] == c) x += suf[i];
        top[i][c] = max(top[i][c], x);
      }
  }
  for (long long i = 0; i < (26); ++i) ans = max(ans, top[n - 1][i]);
  cout << ans << '\n';
}
int main() {
  { ios_base::sync_with_stdio(false); }
  {
    cin.tie(NULL);
    cout.tie(NULL);
  }
  int tc;
  tc = 1;
  for (int t = 0; t < tc; t++) solve(t);
}
