#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char s[N];
long long dp[N][26];
int rec[26], recmax[26];
int main() {
  int n, len, l, r;
  long long ans;
  scanf("%d", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    memset(rec, 0, sizeof(rec));
    memset(recmax, 0, sizeof(recmax));
    for (int j = 1; j <= len; j++) {
      if (j > 1 && s[j] == s[j - 1])
        rec[s[j] - 'a']++;
      else
        rec[s[j] - 'a'] = 1;
      recmax[s[j] - 'a'] = max(recmax[s[j] - 'a'], rec[s[j] - 'a']);
    }
    for (int j = 0; j < 26; j++) {
      dp[i][j] = recmax[j];
      l = 1;
      r = len;
      while (s[l] == 'a' + j && l <= r) l++;
      while (s[r] == 'a' + j && r > l) r--;
      if (l > len)
        dp[i][j] = max(dp[i][j], (dp[i - 1][j] + 1) * len + dp[i - 1][j]);
      else if (dp[i - 1][j])
        dp[i][j] = max(dp[i][j], 0LL + len - r + l);
    }
  }
  ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n][i]);
  printf("%I64d\n", ans);
  return 0;
}
