#include <bits/stdc++.h>
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
inline int POW(int a, int b = 1000000007 - 2, int ans = 1) {
  for (; b; b >>= 1, a = (long long)a * a % 1000000007)
    if (b & 1) ans = (long long)ans * a % 1000000007;
  return ans;
}
inline void rd(int &X) {
  X = 0;
  int w = 0;
  char ch = 0;
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  X = w ? -X : X;
}
int n, ans;
char a[100005];
int L[100005][26], R[100005][26], mx[100005][26], len[100005];
int work(int now) {
  int l = L[1][now], r = R[1][now], MX = mx[1][now];
  for (int i = 2; i <= n; i++)
    if (L[i][now] == len[i]) {
      l = l + (l + 1) * len[i];
      r = r + (r + 1) * len[i];
      MX = MX + (MX + 1) * len[i];
    } else {
      l = L[i][now];
      r = R[i][now];
      if (MX) {
        MX = max(mx[i][now], l + r + 1);
      } else {
        MX = mx[i][now];
      }
    }
  return MX;
}
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", a + 1);
    int m = strlen(a + 1);
    len[i] = m;
    for (int k = 0; k < 26; k++) {
      for (int j = 1; j <= m and a[j] == 'a' + k; j++) L[i][k]++;
      for (int j = m; j >= 1 and a[j] == 'a' + k; j--) R[i][k]++;
      for (int now = 0, j = 1; j <= m; j++)
        if (a[j] == 'a' + k)
          now++, mx[i][k] = max(mx[i][k], now);
        else
          now = 0;
    }
  }
  for (int k = 0; k < 26; k++) ans = max(ans, work(k));
  cout << ans;
}
