#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void redirectIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
vector<long long> getLengts(const string& s) {
  vector<long long> lengths(26);
  int cur = -1;
  int len = -1;
  for (char c : s) {
    int now = c - 'a';
    len++;
    if (now != cur) {
      cur = now;
      len = 1;
    }
    lengths[cur] = max(lengths[cur], (long long)len);
  }
  return lengths;
}
int main() {
  redirectIO();
  int n;
  cin >> n;
  string p;
  cin >> p;
  vector<long long> lengths = getLengts(p);
  for (int j = 0; j < (n - 1); j++) {
    string s;
    cin >> s;
    int suff = s.back() - 'a';
    int slen = 1;
    for (int i = (int)s.length() - 2; i >= 0 && s[i] == s.back(); i--) {
      slen++;
    }
    int pref = s[0] - 'a';
    int plen = 1;
    for (int i = 1; i < s.length() && s[i] == s[0]; i++) {
      plen++;
    }
    vector<long long> curLengths = getLengts(s);
    if (plen == s.length()) {
      for (int i = 0; i < (26); i++) {
        if (i == pref) {
          lengths[i] = lengths[i] + (lengths[i] + 1) * curLengths[i];
        } else
          lengths[i] = min(lengths[i], 1LL);
      }
    } else {
      for (int i = 0; i < (26); i++) {
        if (lengths[i] > 0) {
          lengths[i] = 1 + (pref == i) * plen + (suff == i) * slen;
        }
        lengths[i] = max(lengths[i], curLengths[i]);
      }
    }
    for (int i = 0; i < (26); i++)
      if (lengths[i] > 2e9) lengths[i] = 2e9;
  }
  long long ans = 0;
  for (long long x : lengths) ans = max(ans, x);
  cout << ans << endl;
  return 0;
}
