#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
string s[N];
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    char c = i + 'a';
    long long len = s[1].size();
    long long maxn = 0, summ = 0;
    for (int j = 0; j < len; j++) {
      if (s[1][j] == c)
        if (j == 0 || s[1][j] == s[1][j - 1])
          summ = summ + 1;
        else
          summ = 1;
      maxn = max(maxn, summ);
    }
    for (int j = 2; j <= n; j++) {
      long long maxnn = 0;
      len = s[j].size();
      long long num = 0, summ = 0;
      for (int k = 0; k < len; k++) {
        if (s[j][k] == c) {
          num++;
          if (k == 0 || s[j][k] == s[j][k - 1])
            summ++;
          else
            summ = 1;
        }
        maxnn = max(maxnn, summ);
      }
      if (num == len) {
        maxn = maxn + (maxn + 1) * len;
        continue;
      }
      long long L = 0, R = 0;
      for (int k = 0; k < len; k++)
        if (s[j][k] == c)
          L++;
        else
          break;
      for (int k = len - 1; k >= 0; k--)
        if (s[j][k] == c)
          R++;
        else
          break;
      if (maxn >= 1)
        maxn = max(L + 1 + R, maxnn);
      else
        maxn = max(max(L, R), maxnn);
    }
    ans = max(ans, maxn);
  }
  cout << ans;
}
