#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
  long long data = 0, m = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') {
    m = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = (data << 1) + (data << 3) + (ch ^ 48);
    ch = getchar();
  }
  return (m) ? data : -data;
}
int n, len[2000005], mx[2000005];
char s[2000005];
int Ans;
int main() {
  n = gi();
  for (int i = 'a'; i <= 'z'; i++) len[i] = 0;
  for (int sq = 1; sq <= n; sq++) {
    scanf("%s", s + 1);
    bool flag = true;
    int l = strlen(s + 1);
    for (int i = 1; i <= l; i++)
      if (s[i] != s[1]) {
        flag = false;
        break;
      }
    if (flag) {
      len[s[1]] = l * (len[s[1]] + 1) + len[s[1]];
      for (int j = 'a'; j <= 'z'; j++)
        if (len[j] && j != s[1]) len[j] = 1;
    } else {
      for (int j = 'a'; j <= 'z'; j++) mx[j] = 0;
      for (int pl = 1, pr = 0; pl <= l; pl = pr + 1) {
        pr = pl;
        while (pr + 1 <= l && s[pr + 1] == s[pl]) pr++;
        mx[s[pl]] = max(mx[s[pl]], pr - pl + 1);
      }
      int l1 = 1;
      while (s[l - l1] == s[l]) ++l1;
      int l2 = 0;
      while (s[1 + l2] == s[l]) ++l2;
      if (len[s[l]]) mx[s[l]] = max(mx[s[l]], l1 + l2 + (len[s[l]] != 0));
      mx[s[l]] = max(mx[s[l]], (len[s[l]] != 0) + l1);
      l1 = 1;
      while (s[1 + l1] == s[1]) ++l1;
      mx[s[1]] = max(mx[s[1]], (len[s[1]] != 0) + l1);
      for (int j = 'a'; j <= 'z'; j++)
        if (len[j]) len[j] = 1;
      for (int j = 'a'; j <= 'z'; j++) len[j] = max(len[j], mx[j]);
    }
  }
  for (int j = 'a'; j <= 'z'; j++) Ans = max(Ans, len[j]);
  cout << Ans << endl;
  return 0;
}
