#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
string s[maxn];
int len[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    len[i] = s[i].length();
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    char txt = i + 'a';
    long long cnt = 0;
    for (int j = 1; j <= n; j++) {
      int mx1 = 0, mx2 = 0, tmp = 0, L = 0;
      for (int k = 0; k < len[j]; k++) {
        if (s[j][k] == txt)
          tmp++;
        else
          tmp = 0;
        L = max(L, tmp);
      }
      for (int k = 0; k < len[j]; k++) {
        if (s[j][k] == txt)
          mx1++;
        else
          break;
      }
      for (int k = len[j] - 1; k >= 0; k--) {
        if (s[j][k] == txt)
          mx2++;
        else
          break;
      }
      if (mx1 == len[j]) {
        cnt = cnt + 1LL * (cnt + 1) * mx1;
      } else {
        if (cnt)
          cnt = 1 + mx1 + mx2;
        else
          cnt = max(mx1, mx2);
      }
      cnt = max(cnt, 1LL * L);
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
