#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(int num, int idx) { return num ^ (1 << idx); }
void FS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 100009;
string s[N];
int n, vis[27];
int longest(string &s, char c) {
  int mx = 0, cnt = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == c)
      cnt++;
    else
      cnt = 0;
    mx = max(mx, cnt);
  }
  return mx;
}
int getP(string &s, char c) {
  int cnt = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == c)
      cnt++;
    else
      break;
  }
  return cnt;
}
int getS(string &s, char c) {
  int cnt = 0;
  for (int i = ((int)(s).size()) - 1; i >= 0; i--) {
    if (s[i] == c)
      cnt++;
    else
      break;
  }
  return cnt;
}
int solve(int n, char c) {
  int res = longest(s[1], c);
  for (int i = 2; i <= n; i++) {
    int lgs = longest(s[i], c);
    int prefix = getP(s[i], c);
    int suffix = getS(s[i], c);
    if (lgs == ((int)(s[i]).size())) {
      res = res + lgs * (res + 1);
    } else if (res == 0) {
      res = lgs;
    } else {
      res = max(prefix + suffix + 1, lgs);
    }
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 0; j < ((int)(s[i]).size()); j++) {
      vis[s[i][j] - 'a']++;
    }
  }
  int ans = 1;
  for (int i = 0; i < 26; i++)
    if (vis[i] > 0) ans = max(ans, solve(n, i + 'a'));
  cout << ans << endl;
}
