#include <bits/stdc++.h>
using namespace std;
int n;
long long f[30];
char a[100005];
int la;
long long mx;
long long g[30];
bool check() {
  for (int i = 2; i <= la; ++i)
    if (a[i] != a[i - 1]) return false;
  return true;
}
long long getpre() {
  for (int i = 2; i <= la; ++i)
    if (a[i] != a[i - 1]) return i - 1;
  return la;
}
long long getsuf() {
  for (int i = la - 1; i >= 1; --i)
    if (a[i] != a[i + 1]) return la - (i + 1) + 1;
  return la;
}
int main() {
  scanf("%d", &n);
  scanf("%s", a + 1);
  la = (int)strlen(a + 1);
  for (int i = 1; i <= la; ++i) {
    ++mx;
    f[a[i] - 'a'] = max(f[a[i] - 'a'], mx);
    if (a[i] != a[i + 1]) mx = 0;
  }
  for (int t = 2; t <= n; ++t) {
    scanf("%s", a + 1);
    la = (int)strlen(a + 1);
    if (check()) {
      long long num = f[a[1] - 'a'];
      for (int i = 0; i < 26; ++i)
        if (f[i]) f[i] = 1;
      f[a[1] - 'a'] = num + (num + 1) * la;
    } else {
      mx = 0;
      memset(g, 0, sizeof(g));
      for (int i = 1; i <= la; ++i) {
        ++mx;
        g[a[i] - 'a'] = max(g[a[i] - 'a'], mx);
        if (a[i] != a[i + 1]) mx = 0;
      }
      if (a[1] == a[la]) {
        for (int i = 0; i < 26; ++i)
          if (f[i]) f[i] = 1;
        if (f[a[1] - 'a']) f[a[1] - 'a'] = 1 + getpre() + getsuf();
        for (int i = 0; i < 26; ++i) f[i] = max(f[i], g[i]);
      } else {
        for (int i = 0; i < 26; ++i)
          if (f[i]) f[i] = 1;
        if (f[a[1] - 'a']) f[a[1] - 'a'] = getpre() + 1;
        if (f[a[la] - 'a']) f[a[la] - 'a'] = getsuf() + 1;
        for (int i = 0; i < 26; ++i) f[i] = max(f[i], g[i]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, f[i]);
  printf("%lld\n", ans);
  return 0;
}
