#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
void setmin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void setmax(T& a, T val) {
  if (a < val) a = val;
}
void addmod(long long& a, long long val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
void submod(long long& a, long long val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
long long inv(long long a, int p = MOD) { return fpow(a, p - 2, p); }
const int N = 100005;
int sz[N], arr[N];
string s[N];
long long dp[N][26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < 26; j++) {
    int cnt = 0, ans = 0;
    char ch = 'a' + j;
    for (int k = 0; k < s[0].length(); k++) {
      if (s[0][k] == ch)
        cnt++;
      else {
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    dp[0][j] = max(ans, cnt);
  }
  for (int i = 1; i < n; i++) {
    long long hs[26], lenpre, lensuff;
    int m = s[i].length();
    for (int j = 0; j < 26; j++) {
      long long cnt = 0, ans = 0;
      char ch = 'a' + j;
      for (int k = 0; k < m; k++) {
        if (s[i][k] == ch)
          cnt++;
        else {
          ans = max(ans, cnt);
          cnt = 0;
        }
      }
      hs[j] = max(ans, cnt);
    }
    long long cnt = 0;
    for (int k = 0; k < m; k++) {
      if (s[i][k] == s[i][0])
        cnt++;
      else {
        lenpre = cnt;
        break;
      }
    }
    lenpre = cnt;
    cnt = 0;
    for (int k = m - 1; k >= 0; k--) {
      if (s[i][k] == s[i][m - 1])
        cnt++;
      else {
        lensuff = cnt;
        break;
      }
    }
    lensuff = cnt;
    for (int j = 0; j < 26; j++) {
      char ch = 'a' + j;
      if (ch == s[i][0]) {
        if (lenpre == m)
          dp[i][j] = max(dp[i][j], lenpre * (dp[i - 1][j] + 1) + dp[i - 1][j]);
        else if (s[i][0] == s[i][m - 1])
          dp[i][j] = max(dp[i][j], lenpre + lensuff + min(dp[i - 1][j], 1LL));
        else
          dp[i][j] = max(dp[i][j], lenpre + min(dp[i - 1][j], 1LL));
      }
      if (ch == s[i][m - 1]) {
        if (lensuff == m)
          dp[i][j] = max(dp[i][j], lensuff * (dp[i - 1][j] + 1) + dp[i - 1][j]);
        else if (s[i][0] == s[i][m - 1])
          dp[i][j] = max(dp[i][j], lensuff + lenpre + min(dp[i - 1][j], 1LL));
        else
          dp[i][j] = max(dp[i][j], lensuff + min(dp[i - 1][j], 1LL));
      }
      dp[i][j] = max(dp[i][j], hs[j]);
      dp[i][j] = max(dp[i][j], min(dp[i - 1][j], 1LL));
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n - 1][i]);
  cout << ans << "\n";
  return 0;
}
