#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  bool b = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  if (c == '-') c = getchar(), b = 1;
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (b) x = -x;
}
void reads(std ::string &s) {
  char c;
  while (!isalpha(c = getchar()))
    ;
  s += c;
  while (isalpha(c = getchar())) s += c;
}
using namespace std;
const int N = 1e5 + 11;
int m;
long long n, f[N], ans[50], last[50];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  if (fopen("m"
            ".inp",
            "r")) {
    freopen(
        "m"
        ".inp",
        "r", stdin);
  }
  read(m);
  long long lastl = 0, lastr = 0;
  int chl, chr;
  for (int ii = 1; ii <= m; ii++) {
    s = '#';
    reads(s);
    n = s.size() - 1;
    for (int i = 0; i < 26; i++) ans[i] = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == s[i - 1])
        f[i] = f[i - 1];
      else
        f[i] = 0;
      f[i]++;
      ans[s[i] - 'a'] = max(ans[s[i] - 'a'], f[i]);
    }
    long long l = 1, r = f[n];
    for (int i = 2; i <= n; i++) {
      if (f[i] == 1) break;
      l = f[i];
    }
    if (s[1] == s[n] && last[s[1] - 'a'] > 0)
      ans[s[1] - 'a'] = l + r + 1;
    else
      ans[s[1] - 'a'] = l + (last[s[1] - 'a'] > 0),
                 ans[s[n] - 'a'] = r + (last[s[n] - 'a'] > 0);
    if (l == n) ans[s[1] - 'a'] = last[s[1] - 'a'] + (last[s[1] - 'a'] + 1) * l;
    if (s[1] == chl) l = lastl + (lastl + 1) * l;
    if (s[n] == chr) r = lastr + (lastr + 1) * r;
    for (int i = 0; i < 26; i++) {
      int ooooo = 0;
      if (last[i]) ooooo = 1;
      last[i] = ans[i];
      if (!last[i]) last[i] = ooooo;
    }
    chl = s[1] - 'a';
    chr = s[n] - 'a';
    lastl = l;
    lastr = r;
  }
  long long res = max(lastl, lastr);
  for (int i = 0; i < 26; i++) res = max(res, last[i]);
  cout << res;
}
