#include <bits/stdc++.h>
using namespace std;
int n;
string s[100005];
struct node {
  int l, r, mid;
  bool isall;
};
node a[100005][30];
int dp[100005][30];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    int len = s[i].size();
    for (int j = 0; j < 26; j++) {
      for (int k = 0; k < len; k++) {
        if ('a' + j == s[i][k])
          a[i][j].l++;
        else
          break;
      }
      for (int k = len - 1; k >= 0; k--) {
        if ('a' + j == s[i][k])
          a[i][j].r++;
        else
          break;
      }
      int temp = 0;
      for (int k = 0; k < len; k++) {
        if ('a' + j == s[i][k])
          temp++;
        else {
          a[i][j].mid = max(a[i][j].mid, temp);
          temp = 0;
        }
      }
      a[i][j].mid = max(a[i][j].mid, temp);
      if (temp == len) a[i][j].isall = 1;
    }
  }
  for (int i = 0; i < 26; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j][i].isall)
        dp[j][i] = dp[j - 1][i] + (dp[j - 1][i] + 1) * a[j][i].mid;
      else if (dp[j - 1][i] != 0)
        dp[j][i] = max(a[j][i].mid, a[j][i].l + a[j][i].r + 1);
      else if (dp[j - 1][i] == 0)
        dp[j][i] = a[j][i].mid;
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n][i]);
  printf("%d\n", ans);
  return 0;
}
