#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T> read_n(long long n) {
  vector<T> ret(n);
  for (long long i = 0; i < n; i++) cin >> ret[i];
  return ret;
}
template <typename iter>
void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin) cout << " ";
    cout << *it;
  }
  cout << endl;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<string> s(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<pair<long long, long long> > a(n);
  for (long long i = 0; i < n; i++) {
    long long m = s[i].size();
    long long u = 0, v = 0;
    while (u < m && s[i][u] == s[i][0]) u++;
    while (v < m && s[i][m - v - 1] == s[i][m - 1]) v++;
    a[i] = {u, v};
  }
  auto go = [&](int j, int ch) {
    long long ret = 0;
    long long cur = 0;
    long long m = s[j].size();
    for (long long i = 0; i < m; i++) {
      if (s[j][i] == ch + 'a') {
        cur++;
      } else {
        cur = 0;
      }
      ret = max(ret, cur);
    }
    return ret;
  };
  long long dbg_target = 0;
  long long ret = 1;
  for (long long ch = 0; ch < 26; ch++) {
    long long val = go(0, ch);
    if (ch == dbg_target)
      if (0) cerr << val << endl;
    for (long long i = 1; i < n; i++) {
      long long next = val;
      if (s[i].front() == ch + 'a' && a[i].first == s[i].size()) {
        next = val + (val + 1) * s[i].size();
      } else if (val) {
        next = 1;
        if (s[i].front() == ch + 'a') next += a[i].first;
        if (s[i].back() == ch + 'a') next += a[i].second;
      }
      val = max(next, go(i, ch));
      if (ch == dbg_target)
        if (0) cerr << val << endl;
    }
    ret = max(ret, val);
  }
  cout << ret << "\n";
  return 0;
}
