#include <bits/stdc++.h>
using namespace std;
const long long oo = 2e9;
const long long N = 100100;
const long long root = trunc(sqrt(1e7));
string s, t[N];
bool mrk[100];
long long n, ans = 1, pf = -1, sf, cur;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> s;
    t[i] = s;
    for (long long j = 0; j < (long long)s.size(); j++) mrk[s[j] - 'a'] = 1;
  }
  cin >> s;
  cur = 1;
  for (long long i = 1; i < (long long)s.size(); i++)
    if (s[i] == s[i - 1])
      cur++;
    else {
      if (pf < 0) pf = cur;
      ans = max(ans, cur);
      cur = 1;
    }
  if (pf < 0) pf = cur;
  sf = cur;
  if (pf == (long long)s.size()) {
    ans = sf;
    if (mrk[s[0] - 'a']) {
      cur = 1;
      long long mx = 0;
      for (long long i = 1; i < (long long)t[1].size(); i++)
        if (t[1][i] == t[1][i - 1])
          cur++;
        else {
          if (t[1][i - 1] == s[0]) mx = max(mx, cur);
          cur = 1;
        }
      if (t[1].back() == s[0]) mx = max(mx, cur);
      for (long long it = 2; it < n; it++) {
        long long pref = -1, suf = -1, Mx = 0;
        cur = 1;
        for (long long i = 1; i < (long long)t[it].size(); i++)
          if (t[it][i] == t[it][i - 1])
            cur++;
          else {
            if (pref < 0) pref = (t[it][0] == s[0] ? cur : 0);
            if (t[it][i - 1] == s[0]) Mx = max(Mx, cur);
            cur = 1;
          }
        if (pref < 0) pref = (t[it][0] == s[0] ? cur : 0);
        if (t[it].back() == s[0]) {
          Mx = max(Mx, cur);
          suf = cur;
        } else
          suf = 0;
        if (pref == (long long)t[it].size()) {
          mx = pref * (mx + 1) + mx;
        } else {
          if (mx) mx = pref + suf + 1;
          mx = max(mx, Mx);
        }
      }
      ans = max(ans, mx + sf * (mx + 1));
    }
  } else {
    for (long long i = 0; i < 26; i++) {
      if (!mrk[i]) continue;
      cur = 1;
      if (char('a' + i) == s[0]) cur += pf;
      if (char('a' + i) == s.back()) cur += sf;
      ans = max(ans, cur);
    }
  }
  cout << ans;
}
