#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int add(int a, int b);
inline int mult(int a, int b);
inline int sub(int a, int b);
inline int divv(int a, int b);
string s[100500];
inline int max_length(string &s, char c) {
  int cnt = 0;
  int res = 0;
  for (char a : s) {
    if (a == c)
      cnt++;
    else {
      res = max(res, cnt);
      cnt = 0;
    }
  }
  res = max(res, cnt);
  return res;
}
int32_t main() {
  std::iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    int a = max_length(s[0], c);
    for (int i = 1; i < n; i++) {
      int b = max_length(s[i], c);
      if (b == s[i].size())
        a = b * (a + 1) + a;
      else {
        int a1 = b;
        int pos = 0;
        for (; pos < s[i].size() && s[i][pos] == c; pos++)
          ;
        int pos2 = int(s[i].size()) - 1;
        for (; pos2 >= 0 && s[i][pos2] == c; pos2--)
          ;
        int pref = pos;
        int suf = int(s[i].size()) - pos2 - 1;
        if (a == 0) {
          a = a1;
        } else {
          a = max(a1, pref + suf + 1);
        }
      }
    }
    ans = max(ans, a);
  }
  cout << ans;
  return 0;
}
int add(int a, int b) {
  int result = a + b;
  if (result >= mod) result -= mod;
  return result;
}
int sub(int a, int b) {
  int result = a - b;
  if (result < 0) result += mod;
  return result;
}
int mult(int a, int b) { return (a * 1ll * b) % mod; }
int bin(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = mult(res, a);
    a = mult(a, a);
    n /= 2;
  }
  return res;
}
int divv(int a, int b) { return mult(a, bin(b, mod - 2)); }
