#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - 48, c = getchar();
  return x;
}
long long n, len[100005];
char S[100005];
std::string s[100005];
long long lc, rc;
long long ans, flag;
char lp, rp;
signed main() {
  n = read();
  for (register long long i = 1; i <= n; i++)
    std::cin >> s[i], len[i] = s[i].size();
  lp = s[n][0], rp = s[n][len[n] - 1];
  lc = 1;
  for (register long long i = 1; i < len[n]; i++) {
    if (s[n][i] == s[n][i - 1])
      lc++;
    else
      break;
  }
  rc = 1;
  for (register long long i = len[n] - 2; i >= 0; --i) {
    if (s[n][i] == s[n][i + 1])
      rc++;
    else
      break;
  }
  ans = 1;
  long long now = 1;
  for (register long long i = 1; i < len[n]; i++) {
    if (s[n][i] == s[n][i - 1])
      now++, ans = ((ans) > (now) ? (ans) : (now));
    else
      now = 1;
  }
  if (lc == rc && lc == len[n]) flag = 1;
  for (register long long i = n - 1; i >= 1; --i) {
    if (flag) {
      long long now = 0, t = 0;
      if (s[i][0] == lp) now = t = 1;
      for (register long long j = 1; j < len[i]; j++) {
        if (s[i][j] == lp && s[i][j] == s[i][j - 1])
          now++, t = ((now) > (t) ? (now) : (t));
        else if (s[i][j] == lp)
          now = 1, t = ((t) > (now) ? (t) : (now));
        else
          now = 0;
      }
      if (t != len[i]) flag = 0;
      ans = ((ans) > ((long long)t + ((long long)t + 1ll) * (long long)lc)
                 ? (ans)
                 : ((long long)t + ((long long)t + 1ll) * (long long)lc));
      if (s[i][0] == lp) {
        long long L = 1;
        for (register long long j = 1; j < len[i]; j++) {
          if (s[i][j] == s[i][j - 1] && s[i][j] == rp)
            L++;
          else
            break;
        }
        lc = (L + 1ll) * lc + L;
      }
      if (s[i][len[i] - 1] == lp) {
        long long R = 1;
        for (register long long j = len[i] - 2; j >= 0; --j) {
          if (s[i][j] == s[i][j + 1] && s[i][j] == lp)
            R++;
          else
            break;
        }
        rc = R + (R + 1ll) * rc;
      }
      continue;
    }
    for (register long long j = 0; j < len[i]; j++) {
      if (lp == s[i][j]) ans = ((ans) > (lc + 1) ? (ans) : (lc + 1));
      if (rp == s[i][j]) ans = ((ans) > (rc + 1) ? (ans) : (rc + 1));
      if (lp == rp && lp == s[i][j])
        ans = ((ans) > (lc + rc + 1) ? (ans) : (lc + rc + 1));
    }
  }
  std::cout << ans;
}
