#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> cnt(26);
  string s;
  for (int ss = 0; ss < (int)n; ss++) {
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++) s[i] -= 'a';
    int nfst = 0, nlst = 0;
    while (nfst < s.size() && s[nfst] == s[0]) nfst++;
    while (nlst < s.size() && s[s.size() - nlst - 1] == s.back()) nlst++;
    vector<long long> old(cnt);
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < (int)26; i++) cnt[i] = old[i] > 0;
    if (nfst == s.size())
      cnt[s[0]] = (old[s[0]] + 1) * nfst + old[s[0]];
    else if (s[0] == s.back()) {
      if (old[s[0]]) cnt[s[0]] = nfst + 1 + nlst;
    } else {
      if (old[s[0]]) cnt[s[0]] = nfst + 1;
      if (old[s.back()]) cnt[s.back()] = 1 + nlst;
    }
    char cur = s[0];
    long long streak = 1;
    cnt[cur] = max(cnt[cur], streak);
    for (int i = 1; i < s.size(); i++) {
      if (s[i] == cur)
        streak++;
      else {
        cur = s[i];
        streak = 1;
      }
      cnt[cur] = max(cnt[cur], streak);
    }
    for (int i = 0; i < (int)26; i++) cnt[i] = min(cnt[i], (long long)1e9);
  }
  long long ans = 0;
  for (int i = 0; i < (int)26; i++) ans = max(ans, cnt[i]);
  cout << ans << "\n";
}
