#include <bits/stdc++.h>
using namespace std;
int n, lim, len, a[100005], pre, las, f[30], g[30], ans, s[30], cnt;
char ch[100005];
int gets() {
  int v = 0;
  bool f = 0;
  char ch;
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    v = (v << 3) + (v << 1) + ch - 48;
    ch = getchar();
  }
  return f ? -v : v;
}
void work() {
  for (int i = 1; i <= 26; i++) {
    g[i] = f[i];
    f[i] = 0;
    if (a[1] == i) {
      if (pre == len) {
        f[i] = g[i] + len * (g[i] + 1);
      } else if (a[len] == i) {
        f[i] = pre + las + 1;
      } else {
        f[i] = pre;
        if (g[i] > 0) f[i]++;
      }
    } else if (a[len] == i) {
      f[i] = las;
      if (g[i] > 0) f[i]++;
    } else {
      if (g[i] > 0) f[i] = 1;
    }
    f[i] = max(f[i], s[i]);
  }
}
int main() {
  n = gets();
  lim = 26;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch + 1);
    len = strlen(ch + 1);
    for (int j = 1; j <= lim; j++) s[j] = 0;
    for (int j = 1; j <= len; j++) a[j] = ch[j] + 1 - 'a';
    pre = las = 1;
    for (int j = 2; j <= len; j++)
      if (a[j] == a[j - 1])
        pre++;
      else
        break;
    for (int j = len - 1; j >= 1; j--)
      if (a[j] == a[j + 1])
        las++;
      else
        break;
    cnt = 1;
    a[len + 1] = 0;
    for (int j = 2; j <= len; j++) {
      if (a[j] != a[j - 1]) {
        s[a[j - 1]] = max(s[a[j - 1]], cnt);
        cnt = 1;
      } else
        cnt++;
    }
    s[a[len]] = max(s[a[len]], cnt);
    work();
  }
  for (int j = 1; j <= lim; j++) ans = max(ans, f[j]);
  printf("%d\n", ans);
  return 0;
}
