#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int dp[maxx][30], m[30], t[30];
char s[maxx];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> (s + 1);
    memset(t, 0, sizeof t);
    memset(m, 0, sizeof m);
    int len = strlen(s + 1);
    for (int j = 1; j <= len; j++) {
      if (j != 1 && s[j] == s[j - 1])
        t[s[j] - 'a']++;
      else
        t[s[j] - 'a'] = 1;
      m[s[j] - 'a'] = max(m[s[j] - 'a'], t[s[j] - 'a']);
    }
    for (int j = 0; j < 26; j++) {
      int l = 0, r = 0;
      dp[i][j] = m[j];
      while (l <= len && s[l + 1] == j + 'a') l++;
      while (len - r && s[len - r] == j + 'a') r++;
      if (l == len)
        dp[i][j] = max(dp[i][j], dp[i - 1][j] * (len + 1) + len);
      else if (dp[i - 1][j])
        dp[i][j] = max(dp[i][j], l + r + 1);
      if (i == n) ans = max(dp[i][j], ans);
    }
  }
  cout << ans << endl;
}
