#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1e5 + 10;
const int MS = 30;
const int inf = 1e9;
int dp[MR][MS];
char s[MR];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    scanf("%s", s);
    map<char, int> M;
    pair<int, int> pref, suf;
    int m = strlen(s);
    {
      for (int i = 0; i < m;) {
        int j = i + 1;
        while (j < m && s[j] == s[i]) j++;
        if (!i) pref = make_pair(s[i] - 'a', j - i);
        if (j == m) suf = make_pair(s[i] - 'a', j - i);
        auto it = M.find(s[i] - 'a');
        if (it == M.end())
          M[s[i] - 'a'] = j - i;
        else if (it->second < j - i)
          it->second = j - i;
        i = j;
      }
    }
    if (M.size() == 1) {
      int k = M.begin()->first;
      dp[i][k] =
          min((dp[i - 1][k] + 1) * (long long)m + dp[i - 1][k], (long long)inf);
    } else {
      if (pref.first == suf.first && dp[i - 1][pref.first])
        dp[i][pref.first] = pref.second + suf.second + 1;
      dp[i][pref.first] =
          max(dp[i][pref.first], pref.second + (dp[i - 1][pref.first] ? 1 : 0));
      dp[i][suf.first] =
          max(dp[i][suf.first], suf.second + (dp[i - 1][suf.first] ? 1 : 0));
      for (const auto &p : M) dp[i][p.first] = max(dp[i][p.first], p.second);
    }
    for (int j = ('a'); j < ('z'); ++j)
      if (!dp[i][j - 'a'] && dp[i - 1][j - 'a']) dp[i][j - 'a'] = 1;
  }
  int res = 0;
  for (int i = ('a'); i <= ('z'); ++i) res = max(res, dp[n][i - 'a']);
  printf("%d\n", res);
  return 0;
}
