#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E5 + 10;
char str[MAXN], *cur = str, *sp[MAXN];
long long Ans, tlen;
int L[26], R[26], n, all[26], tL[26], tR[26], tall[26], len[MAXN];
void merge(char *s, int len) {
  int tmplen = tlen;
  memcpy(tL, L, sizeof L);
  memcpy(tR, R, sizeof R);
  memcpy(tall, all, sizeof tall);
  for (int i = 1; i <= len; i++) {
    int x = s[i] - 'a';
    for (int j = 0; j < 26; j++) {
      Ans = max(Ans, (long long)R[j] + (x == j));
      all[j] &= (x == j);
      if (all[j])
        L[j] = R[j] = tlen + 1;
      else
        R[j] = x == j ? R[j] + 1 : 0;
    }
    tlen++;
    for (int j = 0; j < 26; j++) {
      Ans = max(Ans, (long long)R[j] + tL[j]);
      all[j] &= tall[j];
      if (all[j])
        L[j] = R[j] = tlen + tmplen;
      else
        R[j] = tall[j] ? R[j] + tR[j] : tR[j];
    }
    tlen += tmplen;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    sp[i] = cur;
    scanf("%s", sp[i] + 1);
    cur += (len[i] = strlen(sp[i] + 1));
  }
  tlen = strlen(sp[n] + 1);
  int tmx = 0;
  for (int j = 1; j <= len[n]; j++) {
    tmx = sp[n][j] == sp[n][j - 1] ? tmx + 1 : 1;
    Ans = max((long long)tmx, Ans);
  }
  for (int i = 1; i <= tlen; i++)
    for (int j = 0; j < 26; j++)
      L[j] = (L[j] == i - 1) ? (L[j] + (sp[n][i] - 'a' == j)) : L[j];
  for (int i = tlen; i >= 1; i--)
    for (int j = 0; j < 26; j++)
      R[j] = (R[j] == tlen - i) ? (R[j] + (sp[n][i] - 'a' == j)) : R[j];
  for (int i = 0; i < 26; i++)
    all[i] = L[i] == tlen, Ans = max(Ans, (long long)max(L[i], R[i]));
  for (int i = n - 1; i; i--) merge(sp[i], len[i]);
  printf("%lld\n", Ans);
}
