#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
string s[mx];
int fr(char a, int x) {
  int res = 0;
  for (int i = 0; i < s[x].size(); ++i) {
    if (s[x][i] == a)
      res++;
    else
      break;
  }
  return res;
}
int bk(char a, int x) {
  int res = 0;
  for (int i = s[x].size() - 1; i >= 0; --i) {
    if (s[x][i] == a)
      res++;
    else
      break;
  }
  return res;
}
int cal(char a, int x) {
  int res = 0;
  int maxn = -1;
  for (int i = 0; i < s[x].size(); ++i) {
    if (s[x][i] == a) {
      res++;
    } else {
      maxn = max(res, maxn);
      res = 0;
    }
  }
  maxn = max(res, maxn);
  return maxn;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  int ans = -1;
  for (int i = 0; i < 26; ++i) {
    int bef = 0;
    for (int j = 1; j <= n; ++j) {
      int f = fr('a' + i, j);
      if (f == s[j].size()) {
        bef = (bef + 1) * s[j].size() + bef;
      } else {
        int b = bk('a' + i, j);
        int mid = cal('a' + i, j);
        bef = max(mid, bef > 0 ? f + b + 1 : max(b, f));
      }
    }
    ans = max(bef, ans);
  }
  printf("%d\n", ans);
}
