#include <bits/stdc++.h>
using namespace std;
long long dp[100000 + 5][30];
int pre[100000 + 5][30], post[100000 + 5][30], beauty[100000 + 5][30];
string s[100000 + 5];
long long solve(int n, char c) {
  if (dp[n][c - 'a'] >= 0) return dp[n][c - 'a'];
  if (n == 1) return beauty[n][c - 'a'];
  char c1 = s[n][0], c2 = s[n][s[n].length() - 1];
  long long &ret = dp[n][c - 'a'];
  ret = beauty[n][c - 'a'];
  if (solve(n - 1, c) > 0) ret = max(ret, 1ll);
  if (c1 == c && c1 != c2) {
    if (solve(n - 1, c1) > 0) ret = max(ret, (long long)pre[n][c1 - 'a'] + 1);
  } else if (c2 == c && c1 != c2) {
    if (solve(n - 1, c2) > 0) ret = max(ret, (long long)post[n][c2 - 'a'] + 1);
  } else if (c1 == c2 && c1 == c && beauty[n][c1 - 'a'] == s[n].length()) {
    long long t = solve(n - 1, c1);
    ret = max(ret, (long long)s[n].length() * (t + 1) + t);
  } else if (c1 == c2 && c1 == c) {
    if (solve(n - 1, c1) > 0)
      ret = max(ret, (long long)pre[n][c1 - 'a'] + post[n][c1 - 'a'] + 1);
  }
  return ret;
}
char tmp[100000 + 5];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", tmp);
    s[i] = tmp;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 26; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0, t = 0; k <= s[j].length(); k++, t++) {
        if (k == s[j].length() || s[j][k] != i + 'a') {
          pre[j][i] = t;
          break;
        }
      }
      for (int k = s[j].length() - 1, t = 0; k >= -1; k--, t++) {
        if (k == -1 || s[j][k] != i + 'a') {
          post[j][i] = t;
          break;
        }
      }
      for (int k = 0, t = 0; k <= s[j].length(); k++, t++) {
        if (k == s[j].length() || s[j][k] != i + 'a') {
          beauty[j][i] = max(beauty[j][i], t);
          t = -1;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, solve(n, i + 'a'));
  printf("%d\n", ans);
  return 0;
}
