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 double eps = 1e-9;
const int BUFFER_SIZE = 1 << 18;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1 << 30;
const long long LINF = 1ll << 60;
char BUFFER[BUFFER_SIZE];
int gi() {
  int x;
  scanf("%d", &x);
  return x;
}
double gd() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long gll() {
  long long x;
  cin >> x;
  return x;
}
vector<int> gvi(int n) {
  vector<int> a;
  while (n--) a.push_back(gi());
  return a;
}
string gs() {
  scanf("%s", BUFFER);
  return string(BUFFER);
}
template <class T>
struct forArray {
  T *a;
  int n;
  forArray(T *a, int n) : a(a), n(n) {}
};
template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> &d);
template <class T>
ostream &operator<<(ostream &os, const vector<T> &d);
template <class T>
ostream &operator<<(ostream &os, const queue<T> &d);
template <class T>
ostream &operator<<(ostream &os, const stack<T> &d);
template <class T>
ostream &operator<<(ostream &os, const set<T> &d);
template <class T>
ostream &operator<<(ostream &os, const multiset<T> &d);
template <class T>
ostream &operator<<(ostream &os, const unordered_set<T> &d);
template <class A, class B>
ostream &operator<<(ostream &os, const map<A, B> &d);
template <class A, class B>
ostream &operator<<(ostream &os, const multimap<A, B> &d);
template <class A, class B>
ostream &operator<<(ostream &os, const unordered_map<A, B> &d);
template <class T>
ostream &operator<<(ostream &os, const vector<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const queue<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const stack<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const set<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const multiset<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const unordered_set<T> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class A, class B>
ostream &operator<<(ostream &os, const map<A, B> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class A, class B>
ostream &operator<<(ostream &os, const multimap<A, B> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class A, class B>
ostream &operator<<(ostream &os, const unordered_map<A, B> &d) {
  os << "[";
  int f = 0;
  for (auto x : d) {
    if (f) os << ",";
    f = 1;
    os << x;
  }
  return os << "]";
};
template <class T>
ostream &operator<<(ostream &os, const forArray<T> &d) {
  os << "[";
  for (int i = 0; i < d.n; ++i) {
    if (i) os << ",";
    os << d.a[i];
  }
  return os << "]";
}
template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> &d) {
  return os << "[" << d.first << ", " << d.second << "]";
}
int isFull(string &s) {
  for (int i = 1; i < s.size(); ++i)
    if (s[i] != s[0]) return 0;
  return 1;
}
int main() {
  int n = gi();
  vector<long long> L(256, 0);
  for (int i = 0; i < n; ++i) {
    string s = gs();
    if (i == 0) {
      int c = 0;
      for (int i = 0; i < s.size(); ++i) {
        if (!i || s[i] == s[i - 1])
          ++c;
        else
          c = 1;
        L[s[i]] = max(1ll * c, L[s[i]]);
      }
    } else {
      vector<long long> l(256, 0);
      if (isFull(s)) {
        if (L[s[0]] > INF) {
          l[s[0]] = INF;
        } else {
          l[s[0]] = (L[s[0]] + 1) * s.size() + L[s[0]];
        }
        for (char z = 'a'; z <= 'z'; ++z) {
          if (z != s[0] && L[z]) l[z] = 1;
        }
      } else {
        int pr = 0;
        while (pr < s.size() && s[pr] == s[0]) ++pr;
        int sf = 0;
        while (sf < s.size() && s[s.size() - 1 - sf] == s[s.size() - 1]) ++sf;
        for (char z = 'a'; z <= 'z'; ++z) {
          int v = (s[0] == z ? pr : 0) + 1 + (s[s.size() - 1] == z ? sf : 0);
          if (L[z]) l[z] = max(l[z], 1ll * v);
        }
        int c = 0;
        for (int i = 0; i < s.size(); ++i) {
          if (!i || s[i] == s[i - 1])
            ++c;
          else
            c = 1;
          l[s[i]] = max(1ll * c, l[s[i]]);
        }
      }
      L = l;
    }
  }
  int best = 0;
  for (char x = 'a'; x <= 'z'; ++x) best = max(best, (int)L[x]);
  printf("%d\n", best);
  return 0;
}
