#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 100010;
string s[N];
int ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  for (char c = 'a'; c <= 'z'; ++c) {
    int mxlen = 0;
    bool hav = 0;
    for (int i = 1; i <= n; ++i) {
      bool fl = 1;
      for (int j = 0; j < s[i].size(); ++j)
        if (s[i][j] != c) fl = 0;
      int cnt = 0, bb = 0;
      for (int j = 0; j < s[i].size(); ++j) {
        if (s[i][j] == c)
          ++bb;
        else
          bb = 0;
        cnt = max(cnt, bb);
      }
      if (fl) {
        long long t;
        t = mxlen + (long long)(mxlen + 1) * s[i].size();
        if (t > 1e9)
          mxlen = 1e9;
        else
          mxlen = t;
      } else {
        int p = s[i].size() - 1, fi = 0, la = 0;
        while (s[i][p] == c) --p, ++la;
        p = 0;
        while (s[i][p] == c) ++p, ++fi;
        mxlen = (hav ? fi + la + 1 : 0);
      }
      for (int j = 0; j < s[i].size(); ++j) hav |= (s[i][j] == c);
      mxlen = max(mxlen, cnt);
    }
    ans = max(ans, mxlen);
  }
  cout << ans;
}
