#include <bits/stdc++.h>
using namespace std;
long long num[30], pre[100010], cnt;
int main() {
  int n, l, lr, ll;
  char s[100010];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s + 1;
    l = strlen(s + 1);
    for (int j = 0; j < 26; j++)
      if (num[j] && j + 'a' != s[1] && j + 'a' != s[l]) num[j] = 1;
    lr = 1;
    while (s[lr + 1] == s[lr]) lr++;
    ll = l;
    while (lr != l && s[ll] == s[ll - 1]) ll--;
    ll = l - ll + 1;
    if (s[1] == s[l])
      if (lr == l)
        num[s[1] - 'a'] = (l + 1) * num[s[1] - 'a'] + l;
      else
        num[s[1] - 'a'] = lr + ll + 1;
    else {
      num[s[1] - 'a'] = num[s[1] - 'a'] > 0 ? lr + 1 : lr;
      num[s[l] - 'a'] = num[s[l] - 'a'] > 0 ? ll + 1 : ll;
    }
    for (int j = lr + 1; j <= l - ll + 1; j++)
      if (s[j] == s[j - 1])
        pre[j] = pre[j - 1] + 1;
      else {
        pre[j] = 1;
        num[s[j - 1] - 'a'] = max(num[s[j - 1] - 'a'], pre[j - 1]);
      }
  }
  cnt = 0;
  for (int j = 0; j < 26; j++) cnt = max(cnt, num[j]);
  cout << cnt;
}
