#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const long long mod = 1e9 + 7;
int n;
string s[110000];
int ans;
int f[N][26];
int dp[N][26];
int dfs(int id, char x) {
  if (id == 0) return 0;
  int l = 0, r = 0;
  for (int i = 0; i < s[id].size(); i++)
    if (s[id][i] == x)
      l++;
    else
      break;
  for (int i = s[id].size() - 1; i >= 0; i--)
    if (s[id][i] == x)
      r++;
    else
      break;
  if (l == r && l == s[id].size()) {
    return dfs(id - 1, x) * (l + 1) + l;
  } else if (f[id - 1][x - 'a'])
    return max(l + r + 1, dp[id][x - 'a']);
  else
    return dp[id][x - 'a'];
}
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (char x = 'a'; x <= 'z'; x++) {
      int mx = 0, now = 0;
      for (int j = 0; j < s[i].size(); j++)
        if (s[i][j] == x)
          now++;
        else
          mx = max(now, mx), now = 0;
      mx = max(now, mx);
      dp[i][x - 'a'] = mx;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) f[i][j] = f[i - 1][j];
    for (int j = 0; j < s[i].size(); j++) f[i][s[i][j] - 'a'] = 1;
  }
  for (char i = 'a'; i <= 'z'; i++) ans = max(ans, dfs(n, i));
  cout << ans << endl;
  return 0;
}
