#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-8;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
vector<long long> getCnt(string &s) {
  vector<long long> res(26);
  long long len = 1;
  for (int i = 0; i < s.size(); ++i) {
    int c = s[i];
    while (i + 1 < s.size() && s[i + 1] == c) {
      ++len;
      ++i;
    }
    res[c - 'a'] = max(res[c - 'a'], len);
    len = 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string prev;
  cin >> prev;
  vector<long long> &&mx = getCnt(prev);
  for (int i = 1; i < n; ++i) {
    string t;
    cin >> t;
    vector<long long> &&t_mx = getCnt(t);
    for (char c = 'a'; c <= 'z'; ++c) {
      int i = c - 'a';
      if (t_mx[i] == t.size()) {
        mx[i] = min((long long)INF, (long long)t.size() * (mx[i] + 1) + mx[i]);
      } else if (mx[i] > 0) {
        long long pref = 0, suff = 0;
        for (int j = 0; t[j] == c; ++j) ++pref;
        for (int j = t.size() - 1; t[j] == c; --j) ++suff;
        mx[i] = max(t_mx[i], pref + suff + 1);
      } else {
        mx[i] = t_mx[i];
      }
    }
  }
  long long ans = 0;
  for (auto i : mx) ans = max(ans, i);
  cout << ans << '\n';
  return 0;
}
