#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 3e5 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 1000005329;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
int n;
long long a, b, c, mx, ans, nw;
string s[MAX];
int main() {
  cout << fixed << setprecision(10);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> s[i];
  for (char tgt = 'a'; tgt <= 'z'; ++tgt) {
    nw = 0;
    for (long long i = 1; i <= n; ++i) {
      a = b = c = mx = 0;
      reverse(s[i].begin(), s[i].end());
      for (char j : s[i]) {
        if (j != tgt) break;
        ++a;
      }
      reverse(s[i].begin(), s[i].end());
      for (char j : s[i]) {
        if (j != tgt) break;
        ++b;
      }
      for (char j : s[i]) {
        if (j != tgt)
          c = 0;
        else
          ++c, mx = max(c, mx);
      }
      if (mx == s[i].size())
        nw = min(MOD, nw + (nw + 1) * mx);
      else
        nw = max(nw ? a + b + 1 : 0, mx);
    }
    ans = max(ans, nw);
  }
  cout << ans << '\n';
  return 0;
}
