#include <bits/stdc++.h>
using namespace std;
struct str {
  long long cnt[26], len = 0;
  pair<long long, long long> pref = {0, 0}, suf = {0, 0};
  str() { memset(cnt, 0, sizeof(cnt)); }
  str(string s) {
    memset(cnt, 0, sizeof(cnt));
    len = ((int)s.size());
    pair<long long, long long> mx = {0, 0};
    for (int i = 0; i < ((int)s.size()); ++i) {
      if (s[i] - 'a' != mx.first)
        mx = {s[i] - 'a', 1};
      else
        mx.second++;
      cnt[mx.first] = max(cnt[mx.first], mx.second);
    }
    mx = {s[0] - 'a', 0};
    for (int i = 0; i < ((int)s.size()); ++i) {
      if (s[i] - 'a' == mx.first)
        mx.second++;
      else
        break;
    }
    pref = mx;
    mx = {s[((int)s.size()) - 1] - 'a', 0};
    for (int i = ((int)s.size()) - 1; i >= 0; --i) {
      if (s[i] - 'a' == mx.first)
        mx.second++;
      else
        break;
    }
    suf = mx;
  }
};
int n;
void debug(str x) {
  cerr << "x.len"
       << " = " << x.len << endl;
  cerr << "x.pref.first"
       << " = " << x.pref.first << endl;
  cerr << "x.pref.second"
       << " = " << x.pref.second << endl;
  cerr << "x.suf.first"
       << " = " << x.suf.first << endl;
  cerr << "x.suf.second"
       << " = " << x.suf.second << endl;
  for (int i = 0; i < 26; ++i) cout << x.cnt[i] << " ";
  cout << "\n\n";
}
str merge(str A, str B) {
  str ret = str();
  ret.pref = B.pref;
  ret.suf = B.suf;
  if (A.len + B.len > 1e9)
    ret.len = -1;
  else
    ret.len = A.len * B.len + A.len + B.len;
  if (A.pref.second == A.len && B.pref.second == B.len) {
    if (A.pref.first == B.pref.first) {
      ret.pref = ret.suf = {A.pref.first, ret.len};
      ret.cnt[A.pref.first] = ret.len;
    } else {
      ret.cnt[A.pref.first] = 1;
      ret.cnt[B.pref.first] = B.pref.second;
    }
  } else {
    for (int i = 0; i < 26; ++i) {
      ret.cnt[i] = B.cnt[i];
      if (A.cnt[i]) ret.cnt[i] = max(ret.cnt[i], 1LL);
      if (B.pref.second == B.len && i == B.pref.first && A.cnt[i] > 0) {
        ret.cnt[i] = max(ret.cnt[i], B.len * A.cnt[i] + A.cnt[i] + B.len);
        if (A.pref.first == B.pref.first)
          ret.pref = {A.pref.first,
                      B.len * A.pref.second + A.pref.second + B.len};
        if (A.suf.first == B.pref.first)
          ret.suf = {A.suf.first, B.len * A.suf.second + A.suf.second + B.len};
      } else {
        if (i == B.pref.first)
          ret.cnt[i] = max(ret.cnt[i], B.pref.second + (A.cnt[i] > 0));
        if (i == B.suf.first)
          ret.cnt[i] = max(ret.cnt[i], B.suf.second + (A.cnt[i] > 0));
        if (B.pref.first == B.suf.first && B.pref.first == i && A.cnt[i] > 0)
          ret.cnt[i] = max(ret.cnt[i], B.pref.second + B.suf.second + 1);
      }
      if (ret.cnt[i] > 1e9) ret.cnt[i] = 1;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  string s;
  cin >> s;
  str sol = str(s);
  for (int i = 0; i < n - 1; ++i) {
    cin >> s;
    str x = str(s);
    sol = merge(sol, x);
  }
  long long pr = 0;
  for (int i = 0; i < 26; ++i) pr = max(pr, sol.cnt[i]);
  cout << pr;
}
